We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My code works only for the first case, in larger cases I get an error.
Can you give me some advice on how to proceed?
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'solve' function below.## The function is expected to return an INTEGER.# The function accepts following parameters:# 1. INTEGER a# 2. INTEGER b# 3. INTEGER n#defsolve(a,b,n):# First Fibonacci number is aifn==1:returnb# Second Fibonacci number is belifn==2:returna+belse:return(solve(a,b,n-1)+solve(a,b,n-2))%(10**9+7)if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')t=int(input().strip())fort_itrinrange(t):first_multiple_input=input().rstrip().split()a=int(first_multiple_input[0])b=int(first_multiple_input[1])n=int(first_multiple_input[2])result=solve(a,b,n)fptr.write(str(result)+'\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Fibonacci Finding (easy)
You are viewing a single comment's thread. Return to all comments →
My code works only for the first case, in larger cases I get an error. Can you give me some advice on how to proceed?