-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10161.cpp
34 lines (32 loc) · 864 Bytes
/
P10161.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
#include <iostream>
#include <cmath>
typedef unsigned long ul;
int main() {
ul N;
while(true) {
std::cin >> N;
if(N == 0)
return 0;
ul root = (ul)sqrt(N-0.5);
ul square = root*root;
ul remainder = N-square;
ul nextSide = root+1;
//std::cerr << N << ": " << std::endl << "root: " << root << ", square: " << square << ", remainder: " << remainder << ", nextSide: " << nextSide << std::endl;
if(root % 2 == 1) {
if(remainder > nextSide) {
std::cout << nextSide << " " << (2*nextSide-remainder) << std::endl;
}
else {
std::cout << remainder << " " << nextSide << std::endl;
}
}
else {
if(remainder > nextSide) {
std::cout << (2*nextSide-remainder) << " " << nextSide << std::endl;
}
else {
std::cout << nextSide << " " << remainder << std::endl;
}
}
}
}