数学方法:

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. hdu 5363Key Set

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5363 Problem Description soda has a set S with n inte ...

  2. python 加密模块安装

    我们使用Python做加密算法如AES.MD5.SHA等时,需要用到PyCrypto模块 PyCrypto模块的安装方法 1.一般在官方网站下载: https://www.dlitz.net/soft ...

  3. excel筛选两列值是否相同,如果相同返回第三列值

    见图:

  4. No.5 表达式中的陷阱

    1. 关于字符串的陷阱 JVM对字符串的处理 String java = new String("Java"); 创建了几个对象? 2个."Java"直接量对应 ...

  5. 自学Python的点滴

    1.第一天 注释 ——任何在#符号右面的内容都是注释. 注释主要作为提供给程序读者的笔记. 程序应该包含这两行 #!/user/bin/python #Filename:**.py 2.在程序中打开P ...

  6. MVC入门之.Net语法学习

    本节中主要学习.Net框架性语法.开发者可以使用新语法提高编程的效率以及代码的运行效率:其本质都是“语法糖”,由编译器在编译时转成原始语法. u  自动属性 Auto-Implemented Prop ...

  7. 《Programming WPF》翻译 第8章 4.关键帧动画

    原文:<Programming WPF>翻译 第8章 4.关键帧动画 到目前为止,我们只看到简单的点到点的动画.我们使用了To和From属性或者By属性来设计动画--相对于当前的属性值.这 ...

  8. 多系统实现单点登录方案:SSO 单点登录

    一.什么是单点登录SSO(Single Sign-On) SSO是一种统一认证和授权机制,指访问同一服务器不同应用中的受保护资源的同一用户,只需要登录一次,即通过一个应用中的安全验证后,再访问其他应用 ...

  9. hdu 5033 Building (单调栈 或 暴力枚举 )

    Description Once upon a time Matt went to a small town. The town was so small and narrow that he can ...

  10. 新建一个MVCProject 项目

    App_Data文件夹用于存放数据库文件的 App_Start文件夹用于存放Web应用程序启动时需要进行重要配置的类文件 Content 文件夹用于存放主题样式文件 Controllers 文件夹用于 ...