-
Notifications
You must be signed in to change notification settings - Fork 0
/
10161.cpp
42 lines (35 loc) · 861 Bytes
/
10161.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
while(cin >> n, n != 0) {
int root, nextSquare;
root = ceil(sqrt(n));
nextSquare = root * root;
int x, y;
if(nextSquare & 1) { // when nextSquare is odd.
if(nextSquare - n < root) {
x = nextSquare - n + 1;
y = root;
}
else {
x = root;
y = n - (root-1)*(root-1);
}
}
else { // when nextSquare is even.
if(nextSquare - n < root) {
x = root;
y = nextSquare - n + 1;
}
else {
x = n - (root-1)*(root-1);
y = root;
}
}
cout << x << ' ' << y << '\n';
}
return 0;
}