Help me in solving SPCP3 problem

My issue

pls explain the approach for this problem

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	for(int i=0;i<t;i++)
	{
	    int a,b;
	    cin>>a>>b;
	    int count=0;
	    
	    while((a%b)!=0)
	        {
	            a++;
	            b--;
	            count++;
	            if(b==1)
	            {
	                
	                break;
	            }
	            
	        }
	   cout<<count<<endl; 
	}
}

Problem Link: Marbles Practice Coding Problem - CodeChef

@je1047
approach is quite simple u have to apply brute force to it.
plzz refer my c++ solution for better understanding .
ping me in case u get stuck at any point

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int a,b;
	    cin>>a>>b;
	    int a1=a;
	    int b1=b;
	    int cnt=0;
	    while(b>1)
	    {
	        if(a%b==0)
	        {
	            
	            break;
	        }
	        a++;
	        b--;
	        cnt++;
	    }
	  //  cout<<cnt<<endl;
	    a=a1;
	    b=b1;
	    int ans=cnt;
	    cnt=0;
	    while(a>1)
	    {
	        if(a%b==0)
	        {
	       ans=min(ans,cnt);
	        break;
	        }
	        a--;
	        b++;
	        cnt++;
	       
	    }
	   // ans=min(ans,cnt);
	    cout<<ans<<endl;
	}
	return 0;
}

Thanks!