• + 0 comments

    There is an error with fptr.write(result + '\n'). Change it to fptr.write(str(result) + '\n'). The correct code is below.

        def solve(n):
            if 9 % n == 0:
                    print(9)
                    return 9
    
            curr_str = ['9']
            next_str = []
            found = False
    
            while not found:
                for curr in curr_str:
                        a = curr + '0'
                        b = curr + '9'
    
                        if int(a) % n == 0:
                                print(int(a))
                                found = True
                                return int(a)
    
                        if int(b) % n == 0:
                                print(int(b))
                                found = True
                                return int(b)
    
                        next_str.append(str(a))
                        next_str.append(str(b))
    
            curr_str = next_str
            next_str = []
    

    if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')

    t = int(input().strip())
    
    for t_itr in range(t):
        n = int(input().strip())
    
        result = solve(n)
        # fptr.write(result + '\n')
        # add str(result) because otherwise it does not work
        fptr.write(str(result) + '\n')
    
    fptr.close()