Project Euler Problem 25
1000桁を超える最初のfibonacci数は何個目か?
安直に。
target_len = 1000 fib = [1,1,2] index = 3 while len(str(fib[2])) < target_len: index += 1 fib = [fib[1], fib[2], fib[1] + fib[2]] if len(str(fib[2])) >= target_len: print index break
python prog.py 1.46s user 0.00s system 99% cpu 1.466 total