forked from t3nsor/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bmj.cpp
57 lines (57 loc) · 739 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
// 2008-06-26
#include <cstdio>
#include <cmath>
int input()
{
char c=getchar();
if (c==-1) return -1;
else ungetc(c,stdin);
int x=0;
for(;;)
{
c=getchar();
if (c==' '||c=='\n') return x;
x=10*x+c-'0';
}
}
int main()
{
for(;;)
{
int x=input();
int X,Y;
if (x==-1) return 0;
int l=1e-7+(3.0+sqrt(12.0*x-15.0))/6.0;
if (x<=3*l*l-2*l+1)
{
X=3*l*l-2*l+1-x;
Y=l-X;
}
else if (x<=3*l*l-l+1)
{
X=3*l*l-2*l+1-x;
Y=l;
}
else if (x<=3*l*l+1)
{
X=-l;
Y=3*l*l+1-x;
}
else if (x<=3*l*l+l+1)
{
X=x-(3*l*l+l+1);
Y=3*l*l+1-x;
}
else if (x<=3*l*l+2*l+1)
{
X=x-(3*l*l+l+1);
Y=-l;
}
else //x<=3*l*l+3*l+1
{
X=l;
Y=x-(3*l*l+3*l+1);
}
printf("%d %d\n",X,Y);
}
}