数学方法:

Saying that a number contains 1000 digits is the same as
saying that it's greater than 10**999. The nth Fibonacci number is [phi**n / sqrt(5)], where the
brackets denote "nearest integer". So we need phi**n/sqrt(5) > 10**999 n * log(phi) - log(5)/2 > 999 * log(10) n * log(phi) > 999 * log(10) + log(5)/2
n > (999 * log(10) + log(5) / 2) / log(phi) A handheld calculator shows the right hand side to be
4781.8593, so 4782 is the first integer n with the
desired property. Why bother with a computer on this one?

暴力:

import time
start = time.time()
sed_2 = 1
sed_1 = 1
for i in range(3,1000000):
sed = sed_1 + sed_2
# print(sed)
if len(str(sed)) == 1000:
res = i
break
sed_1,sed_2 = sed,sed_1 print(i)
print(time.time()- start) >>>
4782
0.15599989891052246
>>>

project euler 25 fibonacci的更多相关文章

  1. Project Euler 25 1000-digit Fibonacci number

    题意:在斐波那契数列( 1 ,1,2,3,5 ...... )中,第一个有1000位数字的是第几项? 思路:滚动数组 + 大数加法 /********************************* ...

  2. Python练习题 039:Project Euler 011:网格中4个数字的最大乘积

    本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...

  3. Python练习题 037:Project Euler 009:毕达哥拉斯三元组之乘积

    本题来自 Project Euler 第9题:https://projecteuler.net/problem=9 # Project Euler: Problem 9: Special Pythag ...

  4. Python练习题 030:Project Euler 002:偶数斐波那契数之和

    本题来自 Project Euler 第2题:https://projecteuler.net/problem=2 # Each new term in the Fibonacci sequence ...

  5. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  6. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  7. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  8. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  9. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

随机推荐

  1. [转载]移动终端浏览器初始设置apple-mobile-web-app-capable

    这两句话的确很有用,有了它,手机访问的时候像样了. 原文地址:移动终端浏览器初始设置apple-mobile-web-app-capable作者:素水凌心 移动终端浏览器默认设置视口的宽度和初始规模. ...

  2. 微信小程序开发工具 常用快捷键

    格式调整 Ctrl+S:保存文件 Ctrl+[, Ctrl+]:代码行缩进 Ctrl+Shift+[, Ctrl+Shift+]:折叠打开代码块 Ctrl+C Ctrl+V:复制粘贴,如果没有选中任何 ...

  3. WordPress插件开发记录

    1.a标签在新的网页中打开内容     <a href="网址" target="_blank"></a>      2.PDO的$re ...

  4. KEIL C51 Call Tree

    KEIL中函数的调用在其帮助文档中有一个详细的解释,引用如下: The Call Tree The best way to demonstrate how the call tree is gener ...

  5. 浅谈 qmake 之 shadow build(将源码路径和构建路径分开,一套源码要分别用msvc2008、msvc2008、mingw分别编译又不互相干扰)

    shadow build shadow build 是什么东西?就是将源码路径和构建路径分开(也就是生成的makefile文件和其他产物都不放到源码路径),以此来保证源码路径的清洁. 这不是qmake ...

  6. MYSQL连接字符串参数详细解析(大全参考)

    Connector/Net Connection String Options Reference Database=dbname;Data Source=192.168.1.1;Port=3306; ...

  7. 【转】android cts测试方法及步骤

    原文网址:http://blog.csdn.net/shi_xin/article/details/42262675 1.CTS下载 打开下面网址, http://source.android.com ...

  8. 《Algorithms 4th Edition》读书笔记——3.1 符号表(Elementary Symbol Tables)-Ⅱ

    3.1.2 有序的符号表 典型的应用程序中,键都是Comparable的对象,因此可以使用a.compare(b)来比较a和b两个键.许多符号表的实现都利用Comparable接口带来的键的有序性来更 ...

  9. android 缓存Bitmap - 开发文档翻译

    由于本人英文能力实在有限,不足之初敬请谅解 本博客只要没有注明“转”,那么均为原创,转贴请注明本博客链接链接 Loading a single bitmap into your user interf ...

  10. Android Call requires API level 11 (current min is 8)的解决方案

    [错误描述] 在用Eclipse开发过程中,为了兼容Android2.2和4.0以上版本,我在使用Notification类时做了2个版本的代码,代码根据系统版本不同执行相应模块,结果,等我输完代码, ...