HACKER RANK Project Euler 25 - N-Digit Fibonacci Number - Solution.'Py'

Project Euler Challenges-25 - N-Digit Fibonacci Number Solution
Problem Statement
This problem is a programming version of Problem 25 from projecteuler.net
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=1F2=1F3=2F4=3F5=5F6=8F7=13F8=21F9=34F10=55F11=89F12=144

The 12th term, F12, is the first term to contain three digits. 
What is the first term in the Fibonacci sequence to contain N digits?
Input Format 
The first line contains an integer T , i.e., number of test cases. 
Next T lines will contain an integer N.
Output Format 
Print the values corresponding to each test case.
Constraints 
1T5000 
2N5000
Sample Input
2
3
4
Sample Output
12
17

Solution:

from math import log10, ceil, sqrt
t = input()
while (t>0):
    t -= 1
    phi = (1+sqrt(5))/2 
    print int(ceil((input()-1 + log10(5)/2) / log10(phi)))

Thanks for Visiting, Hope this helps you....

Comments

Popular Posts