I'm a trying to calculate the 'nth Fibonacci % m ' for the given values. (Using the pisano's series). Here is the message that the terminal is displaying.
error message->
100 2
Traceback (most recent call last):
File "fibag.py", line 27, in <module>
print(huge_fibo(n,m))
File "fibag.py", line 21, in huge_fibo
return get_fibo(rem) % m
TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'
#uses python3
def pisano_len(m):
prev=0
next=1
for i in range(m*m+1):
prev,next=next,(prev+next)%m
if(prev==0 and next==1):
return i+1
def get_fibo(n):
if(n<1):
return n
prev=0
curr=1
for i in range(n-1):
(prev,curr)=(curr,prev+curr)
return curr
def huge_fibo(n,m):
rem=int(n%pisano_len(m))
return get_fibo(rem) % m
if(__name__=='__main__'):
n,m=map(int,input().split())
print(huge_fibo(n,m))
Cant figure out the reason.
Your get_fibo()
function does not execute a return statement if n == 1
, effectively returning None
.