Help me in solving SPCP3 problem

My issue

My solution is exactly matching with the Sample 1 test case and the code is also running fine with no errors. But while submitting, it is not even passing single test case there. Why is that so ?

My code

#include <iostream>
using namespace std;
int findMin(int a, int b){
    int count = 0;
    if (a % b == 0)
        return 0;
    else {
        while (a % b != 0){
            count++;
            b--;
            a++;
        }
    }
    return count;
}
int main() {
	int t;
	cin >> t;
	while (t--){
	    int a, b, ans = 0;
	    cin >> a >> b;
	    ans = findMin(a, b);
	    cout << ans << endl;
	}
	return 0;
}

Problem Link: Marbles Practice Coding Problem - CodeChef

@luckyx100
for test case
1
65 31
your output is 7
but the correct output is 1

You have to see both the cases

  1. you increase ‘a’ and decrease ‘b’
  2. you decrease ‘a’ and increase ‘b’
    also use flags to find out whether you even have the case where chef marbles are divisible if not then give that particular count value a pretty big number