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

原创 2012年03月22日 10:43:20

The Fibonacci sequence is defined by the recurrence relation:

Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.

Hence the first 12 terms will be:

F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
F6 = 8
F7 = 13
F8 = 21
F9 = 34
F10 = 55
F11 = 89
F12 = 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


相关文章推荐

欧拉项目 Problem 17 of how many letters would be used?

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + ...

fibonacci sequence C++ 大数运算

  • 2015年12月25日 16:19
  • 113KB
  • 下载

【算法详解】斐波那契数列 - Fibonacci sequence

1. 斐波那契数列定义 2. 算法 求解斐波那契数列的第n个数: 2.1 递归/分治法 #include #include using namespace std; unsigned ...

fibonacci sequence

数据结构里有道题目是这样描述的:已知k 阶裴波那契序列的定义为 :     f0=0,  f1=0,  ...,  fk-2=0,  fk-1=1;     fn=fn-1+fn-2+...+...

C++ 斐波那契数列(Fibonacci Sequence)

C++ 斐波那契数列(Fibonacci Sequence)一、斐波那契数列指的是这样一个数列:0、1、1、2、3、5、8、13、21、34、…… 在数学上,斐波纳契数列以如下被以递归的方法定义:F...

ZOJ 3952 Fibonacci Sequence Chicken Edition

Year 2017 is the year of chicken, so in this problem we introduce you an interesting programming lan...

[POJ3070]Fibonacci sequence——矩阵+快速幂

斐波那契数列题目描述 斐波那契数列是由如下递推式定义的数列 F0=0F_0=0 F1=1F_1=1 Fn+1=Fn+1+FnF_{n+1}=F_{n+1}+F_n 求这个数列第n项的值对10...

斐波那契数列 1133. Fibonacci Sequence

1133. Fibonacci Sequence Time limit: 1.0 second Memory limit: 64 MB is an infinite sequen...

JZOJ1240. Fibonacci sequence

题目分析斐波拉契数列是大家所熟悉的,至于怎样求斐波拉契数列的第N项相信大家都知道。我们用sumsum 来表示前缀和 sumn=∑ni=1fisum_n=\sum_{i=1}^{n}f_i,fif_i...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:欧拉项目 Problem 25 of in the Fibonacci sequence to contain 1000 digits
举报原因:
原因补充:

(最多只允许输入30个字)