WA for SPCP3 problem

Problem: Marbles
Here is the problem statement
Marbles

Despite multiple attempts, I get a WA. Can someone please tell me the mistake or give me some test cases to figure out the bug in my code.

Here’s my solution
My code

I saw your code,
image

  • How the 1st line is working (I dont know cpp)? p==0 and p==1 at the same time. Correct this one into p==0 and q==0 if it was wrong.
  • The 2nd condition should be
    if(p==0) && (q!=0). Because q may never exist.
  • I did write the exact logic but in python.
# cook your dish here
for _ in range(int(input())):
    a,b = map(int,input().split())
    c,d = a,b
    count1,count2 = 0,0
    while (a%b) and a>=1:
        a+=1
        b-=1
        count1+=1
    while c%d and c>=1:
        c-=1
        d+=1
        count2+=1
    if (count1<count2 and a%b==0) or c==0:
        print(count1)
    else:
        print(count2)
1 Like

Got it. Thanks