The Fibonacci sequence is defined by the following recurrence formula:
Fn = Fn-1 + Fn-2, where F1 = 1, F2 = 1. The first 12 terms are:
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 twelfth term, the first term in which F12 has three digits.
Answer the number of the first term that will be 1000 digits. http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2025
I wrote it in the code as it is.
import math
def main():
(n1, n2) = (1,1)
N = 10
MAX_N = 1000-1
n = 2
while math.log(n2, N)<MAX_N:
(n1,n2) = (n2, n1+n2)
n += 1
print n
main()
Recommended Posts