欧拉项目 Problem 25 of in the Fibonacci sequence to contain 1000 digits

The Fibonacci sequence is defined by the recurrence relation:

F n = F n−1 + F n−2, where F 1 = 1 and F 2 = 1.

Hence the first 12 terms will be:

F 1 = 1
F 2 = 1
F 3 = 2
F 4 = 3
F 5 = 5
F 6 = 8
F 7 = 13
F 8 = 21
F 9 = 34
F 10 = 55
F 11 = 89
F 12 = 144

The 12th term, F12, is the first term to contain three digits.

What is the first term in the Fibonacci sequence to contain 1000 digits?


http://projecteuler.net/problem=25





import java.math.BigInteger;


public class VeryBigInteger {
	public static void main(String args[]){
		BigInteger[] bi=new BigInteger[40000000];
		bi[0]=new BigInteger("1");
		bi[1]=new BigInteger("1");
		for(int i=2;i<bi.length;i++){
			bi[i]=bi[i-1].add(bi[i-2]);
			if((""+bi[i]).length()>=1000){
				System.out.println("i="+i);
				System.out.println("bi[i]="+bi[i]);
				break;
			}
		}
	}
}



i=4781
bi[i]=1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值