/home/toolbox/public_html/solutions/101/10161/10161.cpp
1 #include <iostream>
2 #include <cmath>
3
4 using namespace std;
5
6 long largest_square(long m)
7 {
8 long x, y, ret;
9 for(x = 2; (int)pow((long double)x, (long double)2) < m; x++) { }
10 x--;
11 ret = (int)pow((long double)x, (long double)2);
12 if(ret == m)
13 {
14 x--;
15 ret = (int)pow((long double)x, (long double)2);
16 }
17 return ret;
18 }
19
20 void parse(long m)
21 {
22 if(m==1)
23 {
24 cout << 1 << " " << 1 << endl;
25 return;
26 }
27 int x, y;
28 int n = largest_square(m);
29 long int sqrt_n = (int)sqrt(n);
30 //cout << m << " " << n << endl;
31 if(sqrt_n % 2 == 0)
32 {
33 if(m - n + sqrt_n+ 1 < m)
34 {
35 x = sqrt_n+1;
36 y = m-n;
37 }
38 else if((m - n + sqrt_n + 1) == m)
39 {
40 x = sqrt_n + 1;
41 y = sqrt_n + 1;
42 }
43 else if(m - n + sqrt_n + 1 > m)
44 {
45 x = pow((long double)(sqrt_n + 1), (long double)2) - m + 1;
46 y = sqrt_n + 1;
47 }
48 }
49 else
50 {
51
52 }
53 cout << x << " " << y << " " << endl;
54 }
55
56 int main(void)
57 {
58 long x;
59 while(cin >> x)
60 {
61 //cout << x << endl;
62 if(x == 0)
63 {
64 break;
65 }
66 else
67 {
68 parse(x);
69 }
70 }
71 return 0;
72 }
73