Last two digits Fibonacci number Python
PROGRAM TO FIND LAST TWO DIGITS OF N'TH FIBONACCI NUMBER.
OUTPUT
1 61 13 53
def precomput(f): # 0th and 1st number of the series # are 0 and 1 f.append(0) f.append(1) # Add the previous 2 numbers in the series # and store last two digits of result for i in range(2,300): f.append((f[i-1] + f[i-2]) % 100) # Returns last two digits of # n'th Fibonacci Number def findLastDigit(f,n): return f[n%300] # driver code f = list() precomput(f) n = 1print(findLastDigit(f, n)) n = 61print(findLastDigit(f, n)) n = 7print(findLastDigit(f, n)) n = 67print(findLastDigit(f, n))
1 61 13 53
Comments
Post a Comment