My solution is passing test case but only problem it is showing error of time limit exceeded . Can someone help me to optimised the code
# cook your dish here
t = int(input())
for _ in range(t):
a,b,x = map(int,input().split(' '))
mini = min(a,b)
maxi = max(a,b)
while maxi - mini > 0 :
mini = mini + x
maxi = maxi - x
if maxi == mini :
Problem Link: EQUALIZEAB Problem - CodeChef
I love your appreach and how you went through with the code. but i think there probably is a test case where A=999999999999999999999999999999999, B=1 and X=1.
So, stuff like this will cross the time limit.
Soln: You may instead try the approach i tried. what i did was, check if A-B OR B-A is divisible by 2*X, and if Yes, output is yes, if no, out put is no. [make sure to also take care or A=B or else zero division error may occur.]
Because, subtracting the difference by 2X is the same thing as adding the lesser one with x and subracting x from the greater one.
Since simply checking if i subracted 2X from the difference n times will make it zero is basically
the same as divisibility test.