forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path65.java
More file actions
33 lines (32 loc) · 752 Bytes
/
65.java
File metadata and controls
33 lines (32 loc) · 752 Bytes
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
import java.math.BigInteger;
public class Euler {
public static void main(String args[]) {
BigInteger a = BigInteger.ONE;
BigInteger b = BigInteger.ZERO;
for (int i = 99; i >= 1; --i) {
BigInteger t = BigInteger.ONE;
if (i % 3 == 2) {
t = BigInteger.valueOf((i + 2) / 3 * 2);
}
t = t.multiply(a);
b = b.add(t);
BigInteger g = b.gcd(a);
a = a.divide(g);
b = b.divide(g);
BigInteger tmp = a;
a = b;
b = tmp;
}
b = b.add(a.shiftLeft(1));
BigInteger g = b.gcd(a);
a = a.divide(g);
b = b.divide(g);
System.out.println(b + "/" + a);
String str = b.toString();
int res = 0;
for (int i = 0; i < str.length(); ++i) {
res += str.charAt(i) - '0';
}
System.out.println(res);
}
}