Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
int n;
while(t--){
cin>>n;
int i = 0;
int dif;
while(true){
i++;
dif = n - (i * (i-1) + 1) ;
dif *= dif > 0 ? 1 : -1;
if(dif < i){
break;
}
}
dif = n - (i * (i-1) + 1) ;
if(dif > 0){
cout<<i<<" "<<(i - dif)<<endl;
continue;
}
cout<<(i+dif)<<" "<<i<<endl;
}
}
Copy The Code &
Try With Live Editor
Input
7
11
14
5
4
1
2
1000000000
11
14
5
4
1
2
1000000000
Output
2 4
4 3
1 3
2 1
1 1
1 2
31623 14130
4 3
1 3
2 1
1 1
1 2
31623 14130
Demonstration
Codeforcess Solution 1560-C C. Infinity Table ,C++, Java, Js and Python ,1560-C,Codeforcess Solution