No_25:1000-digit Fibonacci number
2014-04-23 10:04
399 查看
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn
![](http://projecteuler.net/images/symbol_minus.gif)
1 +
Fn
![](http://projecteuler.net/images/symbol_minus.gif)
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?
解题思路:
死办法,对每一个求得位数是否是1000位
1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816
4782
0:00:00.140000
Fn = Fn
![](http://projecteuler.net/images/symbol_minus.gif)
1 +
Fn
![](http://projecteuler.net/images/symbol_minus.gif)
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?
解题思路:
死办法,对每一个求得位数是否是1000位
import datetime start_time=datetime.datetime.now() a,b,index=1,1,2 while 1: a,b,index=a+b,a,index+1 if len(str(a))==1000: print a print index break end_time=datetime.datetime.now() print end_time-start_time结果为:
1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816
4782
0:00:00.140000
相关文章推荐
- SQL语句学习之路6
- ld.info链接脚本
- hour:24小时制和12小时制
- iOS:苹果推送(二)----pem证书的生成
- 撒的撒的
- Makefile 中:= ?= += =的区别
- winXP系统该如何手动安装TCP/IP协议
- 唯一ID生成器算法
- xSlider 可左右、上下图片切换的无缝滚动效果
- 软件开发基础
- 状态模式-设计模式系列
- mysql清除binlog
- K-means聚类算法
- asp.net 心得 ---- 比较意识流
- linux下nginx的安装
- python中的静态方法、类方法解读
- Doxygen 使用总结
- 秒杀宋庆老师的一个不等式猜想
- 【007】栈和队列
- html 空白汉字占位符