-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp057.java
More file actions
32 lines (25 loc) · 790 Bytes
/
p057.java
File metadata and controls
32 lines (25 loc) · 790 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
package level03;
import java.math.BigInteger;
import org.junit.Test;
import lib.EulerTest;
public class p057 extends EulerTest {
final int N = 1000;
final int NUM = 3, DEN = 2;
/**
* Find the number of the first N continued fraction approximations A/B to √2, starting with
* NUM/DEN, such that A has more digits than B.
* <p>
* Given the approximation A/B, the next approximation is 1+1/(1+A/B) = (A+2B)/(A+B).
*/
@Test
public void test() {
BigInteger num = big(NUM), den = big(DEN);
for (int i = 0; i < N; i++) {
if (num.toString().length() > den.toString().length())
ans++;
num = num.add(den).add(den);
den = num.subtract(den);
}
check(153);
}
}