-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibsieveFantabulous.java
More file actions
68 lines (58 loc) · 1.4 KB
/
FibsieveFantabulous.java
File metadata and controls
68 lines (58 loc) · 1.4 KB
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
60
61
62
63
64
65
66
67
68
/* http://lightoj.com/volume_showproblem.php?problem=1008&language=english&type=pdf
Fibsieve Fantabulous
#implementation
*/
import java.util.Scanner;
class FibsieveFantabulous {
static class Node {
long x, y;
Node(long x, long y) {
this.x = x;
this.y = y;
}
}
public static Node getPosition(long time) {
long bound;
double val = Math.sqrt(time);
if (val > (double) (long) (val)) {
bound = (long) (val) + 1;
} else {
bound = (long) (val);
}
long x, y;
long midPos = (long) Math.pow(bound, 2) - bound + 1;
boolean xflg = false;
if (bound % 2 != 0) {
xflg = true;
}
if (xflg) {
if (time > midPos) {
y = bound;
x = bound - Math.abs(time - midPos);
} else {
x = bound;
y = bound - Math.abs(time - midPos);
}
} else {
if (time > midPos) {
x = bound;
y = bound - Math.abs(time - midPos);
} else {
y = bound;
x = bound - Math.abs(time - midPos);
}
}
return new Node(x, y);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testcases = sc.nextInt();
long time;
Node position;
for (int t = 1; t < testcases + 1; t++) {
time = sc.nextLong();
position = getPosition(time);
System.out.println("Case " + t + ": " + position.x + " " + position.y);
}
}
}