-
Notifications
You must be signed in to change notification settings - Fork 103
/
BMJ.cpp
59 lines (57 loc) · 887 Bytes
/
BMJ.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
USER: zobayer
TASK: BMJ
ALGO: ad-hoc
*/
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
int n, x, y, r;
while(scanf("%d",&n)==1) {
r = x = (-3+(int)sqrt(12*n-3))/6, y = 0;
n -= 3*r*r + 3*r + 1;
if(n==0) {
printf("%d %d\n",x,y);
continue;
}
n--, y++;
if(n==0) {
printf("%d %d\n",x,y);
continue;
}
if(n <= r) {
x -= n, y += n;
printf("%d %d\n",x,y);
continue;
}
x = 0, y = r+1, n -= r;
if(n <= r+1) {
x -= n;
printf("%d %d\n",x,y);
continue;
}
x = -r-1, n -= r+1;
if(n <= r+1) {
y -= n;
printf("%d %d\n",x,y);
continue;
}
y = 0, n -= r+1;
if(n <= r+1) {
x += n, y -= n;
printf("%d %d\n",x,y);
continue;
}
x = 0, y = -r-1, n -= r+1;
if(n <= r+1) {
x += n;
printf("%d %d\n",x,y);
continue;
}
x = r+1, n -= r+1;
y += n;
printf("%d %d\n",x,y);
}
return 0;
}