• + 0 comments

    I don't why there is Run Time ERROR (for higher values of a,b,c) even in time complexicity O(n).

    for _ in range(int(input())):
        a,b,c=map(int,input().split())
        x=int(c/(a+(b/a)*b))
        m,n=x,x
        while True:
            if m>0:
                y=(c-a*m)/b
                if y==int(y):
                    print(str(m)+" "+str(int(y)))
                    break
                m-=1
            y=(c-a*n)/b
            if n>0 and y==int(y):
                print(str(n)+" "+str(int(y)))
                break
            n+=1