Dynamic programming
Question 1 : Nth Fibonacci Number
Input:
The first line of input contains T denoting the number of testcases.Then each of the T lines contains a single positive integer N.
Output:
Output the Nth fibonacci number.
Constraints:
1 <= T <= 200
1 <= N <= 1000
Example:
Input:
3
1
2
5
Output:
1
1
5
Solution:
#code
t=int(input())
for i in range(t):
n=int(input())
if(n==0):
print(0)
elif(n==1):
print(1)
else:
l=[0,1]
for j in range(2,n+1):
l.append(0)
for j in range(2,n+1):
l[j]=(l[j-1]+l[j-2])
print(l[n]%1000000007)
0 Comments