观察这个分子序列 设分子为b序列 ,分母为a 序列
则他们满足一下条件
a[i] = a[i - 1] * 2 + a[i - 2]
b[i] = b[i - 1] * 2+b[i - 2]
然后就发现需要高精度
复制代码
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
31import java.math.*; import java.util.*; public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub BigInteger a[] = new BigInteger [1111]; BigInteger b[] = new BigInteger [1111]; a[0] = BigInteger.valueOf(1); b[0] = BigInteger.valueOf(1); a[1] = BigInteger.valueOf(2); b[1] = BigInteger.valueOf(3); for(int i = 2; i <= 1000; i++) { a[i] = a[i - 1].multiply(BigInteger.valueOf(2)).add(a[i - 2]); b[i] = b[i - 1].multiply(BigInteger.valueOf(2)).add(b[i - 2]); } int ans = 0; for(int i = 2; i <= 1000; i++) { if(b[i].toString().length() > a[i].toString().length()) ans++; } System.out.println(ans); } }
最后
以上就是搞怪咖啡最近收集整理的关于Project Euler problem 57的全部内容,更多相关Project内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复