project euler 25 fibonacci
数学方法:
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的更多相关文章
- Project Euler 25 1000-digit Fibonacci number
题意:在斐波那契数列( 1 ,1,2,3,5 ...... )中,第一个有1000位数字的是第几项? 思路:滚动数组 + 大数加法 /********************************* ...
- Python练习题 039:Project Euler 011:网格中4个数字的最大乘积
本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...
- Python练习题 037:Project Euler 009:毕达哥拉斯三元组之乘积
本题来自 Project Euler 第9题:https://projecteuler.net/problem=9 # Project Euler: Problem 9: Special Pythag ...
- Python练习题 030:Project Euler 002:偶数斐波那契数之和
本题来自 Project Euler 第2题:https://projecteuler.net/problem=2 # Each new term in the Fibonacci sequence ...
- [project euler] program 4
上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
- Project Euler 9
题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...
- 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 ...
- project euler 169
project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...
随机推荐
- linq学习三个实例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- [UVA] 784 - Maze Exploration
Maze Exploration A maze of rectangular rooms is represented on a two dimensional grid as illustra ...
- Unity3D使用NGUI做个弹窗
主要函数: NGUITools.AddChild(gameobj, prefab);//gameobj为父对象,prefab为要显示的窗体对象预制 然后写个方法,限制出现多个即可
- HTML5实战之桌面通知
桌面通知功能能够让浏览器即使是最小化状态也能将消息通知给用户.这和WebIM是最为天然的结合.不过,目前支持Desktop Notification功能的浏览器只有Chrome5+. 关于通知的基础知 ...
- cf C. Quiz
http://codeforces.com/contest/337/problem/C 得到的分数为:(2^1+2^2+...+2^X)*k + m-X*k = (2^(X+1)-2)*k + m-X ...
- ActiveX in QT
http://doc.qt.io/qt-4.8/activeqt.htmlhttp://doc.qt.io/qt-5/activeqt-index.html
- 全局函数的Result一定要每次都初始化,否则上次的结果会被保持到下一次继续使用
测试半天,原来是因为这个原因.下面例子中,Result:=''必须写,否则其结果会被累计,真是昏倒!! function MyPaths(tache: IXMLTaskType) : String; ...
- spring bean初始化和销毁
spring bean的创建与消亡由spring容器进行管理,除了使用<bean><property/></bean>进行简单的属性配置之外,spring支持更人性 ...
- /etc/fstab 文件详解 及 /etc/mtab
/etc/fstab 文件解释 文件fstab包含了你的电脑上的存储设备及其文件系统的信息.它是决定一个硬盘(分区)被怎样使用或者说整合到整个系统中的唯一文件. 这个文件的全路径是/etc/fstab ...
- Reverse Linked List II 解答
Question Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Giv ...