概述
观察这个分子序列 设分子为b序列 ,分母为a 序列
则他们满足一下条件
a[i] = a[i - 1] * 2 + a[i - 2]
b[i] = b[i - 1] * 2+b[i - 2]
然后就发现需要高精度
import 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 Euler problem 57所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复