• + 0 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?

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    #
    # 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
    #
    
    def solve(a, b, n):
        # First Fibonacci number is a
        if n == 1:
            return b
        # Second Fibonacci number is b
        elif n == 2:
            return a+b
        else:
            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())
    
        for t_itr in range(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()