-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsandbox.java
More file actions
35 lines (26 loc) · 1.02 KB
/
sandbox.java
File metadata and controls
35 lines (26 loc) · 1.02 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
package project_beuler;
import java.math.BigInteger;
public class sandbox {
public static void main(String[] args) {
// TODO Auto-generated method stub
int counter = 0;
int i = 100;
BigInteger[] frac = addFrac( new BigInteger[]{BigInteger.valueOf(1), BigInteger.valueOf(1)}, inverse(root2(i)) );
if( (frac[0]+"").length() > (frac[1]+"").length() ) {
counter++;
}
System.out.println(frac[0] +" / "+ frac[1]);
System.out.println( (frac[0]+"").length() );
}
public static BigInteger[] root2(int n) {
if( n == 0 )
return new BigInteger[]{BigInteger.valueOf(2), BigInteger.valueOf(1)};
return addFrac( new BigInteger[]{BigInteger.valueOf(2), BigInteger.valueOf(1)}, inverse(root2(n-1)) );
}
public static BigInteger[] addFrac(BigInteger[] first, BigInteger[] second) {
return new BigInteger[] {first[0].multiply(second[1]).add(first[1].multiply(second[0])), first[1].multiply(second[1])};
}
public static BigInteger[] inverse(BigInteger[] frac) {
return new BigInteger[] { frac[1], frac[0] };
}
}