projecteuler---->problem=25----1000-digit Fibonacci number

问题描述:

The Fibonacci sequence is defined by the recurrence relation:

Fn = Fn1 + Fn2,
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?

翻译:

Fibonacci数列的定义如下:

Fn
= Fn-1
+ Fn-2且F1
= 1, F2
= 1。

于是前12个Fibonacci数就是:

  • F1
    = 1
  • F2
    = 1
  • F3
    = 2
  • F4
    = 3
  • F5
    = 5
  • F6
    = 8
  • F7
    = 13
  • F8
    = 21
  • F9
    = 34
  • F10
    = 55
  • F11
    = 89
  • F12
    = 144

第十二项F12,是第一个达到三位数的Fibonacci数。

第一个达到1000位的Fibonacci数又是多少呢?

解答:

def isok(a):
    count=0
    while a>0:
        a/=10
        count+=1
    if count==1000:
        return True
    return False

a,b,c=1,1,0
count=2
while True:
    c=a+b
    count+=1
    if isok(c):
        break
    a=b
    b=c
print count

projecteuler---->problem=25----1000-digit Fibonacci number

时间: 2024-08-29 23:22:08

projecteuler---->problem=25----1000-digit Fibonacci number的相关文章

【HDOJ】3509 Buge's Fibonacci Number Problem

快速矩阵幂,系数矩阵由多个二项分布组成.第1列是(0,(a+b)^k)第2列是(0,(a+b)^(k-1),0)第3列是(0,(a+b)^(k-2),0,0)以此类推. 1 /* 3509 */ 2 #include <iostream> 3 #include <string> 4 #include <map> 5 #include <queue> 6 #include <set> 7 #include <stack> 8 #incl

Buge&#39;s Fibonacci Number Problem

Buge's Fibonacci Number Problem Description snowingsea is having Buge’s discrete mathematics lesson, Buge is now talking about the Fibonacci Number. As a bright student, snowingsea, of course, takes it as a piece of cake. He feels boring and soon com

hdu 3509 Buge&#39;s Fibonacci Number Problem

点击此处即可传送 hdu 3509 题目大意:F1 = f1, F2 = f2;; F(n) = a*F(n-1) + b*F(n-2); S(n) = F1^k + F2^k +-.+Fn^k; 求S(n) mod m; 解题思路: 1:首先一个难题就是怎么判断矩阵的维数(矩阵的维数是个变量) 解决方法:开一个比较大的数组,然后再用一个公有变量记一下就行了,具体详见代码: 2:k次方,找规律: 具体上代码吧: /* 2015 - 8 - 16 晚上 Author: ITAK 今日的我要超越昨日

Project-Euler problem 1-50

最近闲的做了下Project Euler 上的题目,前面50题都比较简单,简单总结下.代码一般是Python和C/C++的 用Python 做这些题目简直是酸爽啊 一下代码可能不一定是我的,因为不知道论坛里面的回复不是永久的,所以我的代码有的丢了,可能找个和我的意思相近的代码.题目翻译是从 欧拉计划 | Project Euler 中文翻译站上面Copy 的表告我. Problem 1  Multiples of 3 and 5 10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是

欧拉计划(python) problem 25

1000-digit Fibonacci number Problem 25 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 =

Fibonacci number

https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Mock%20Interviews/Large%20Search%20Engine%20Company%20/Search%20Engine%20Company%20-%20Interview%20Problems%20-%20SOLUTIONS/Phone%20Screen.ipynb Phone Sc

1150 Travelling Salesman Problem (25 分)

1150 Travelling Salesman Problem (25 分) The "travelling salesman problem" asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and retu

(斐波那契总结)Write a method to generate the nth Fibonacci number (CC150 8.1)

根据CC150的解决方式和Introduction to Java programming总结: 使用了两种方式,递归和迭代 CC150提供的代码比较简洁,不过某些细节需要分析. 现在直接运行代码,输入n(其中用number代替,以免和方法中的n混淆)的值,可以得出斐波那契数. 代码如下: /* CC150 8.1 Write a method to generate the nth Fibonacci number Author : Mengyang Rao note : Use two me

Project Euler:Problem 25 1000-digit Fibonacci number

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, F1