Help me in solving SINS problem

My issue

resolve the time limit issue in this…

My code

#include <iostream>
#define ll long long int
using namespace std;
   ll total_candies(ll  x,ll  y){
       if(x==y ){
           return x+y;
       }
       else if(x==0 && y>0){
           return y;
       }
      else if(y==0 && x>0){
          return x;
      }
      else{
          if(x>y){
         return total_candies(x-y,y);}
          else if(x<y){
           return   total_candies(x,y-x);}
          }
      }
int main() {
	// your code goes here
	ll t;
	cin>>t;
	while(t--){
	    ll x,y;
	    cin>>x>>y;
	    cout<<total_candies(x,y)<<endl;
	}
	return 0;
}

Problem Link: SINS Problem - CodeChef

As for x>y, you have to do x-y till x-y < y. Instead of total_candies(x-y,y), you can use (x%y, y) and similar to (x,y-x) as (x,y%x).

It not give right ans, can you send your code

Because of (x%y, y) you may get x%y = 0, in this case x = y, so have to return 2*y.

int func(int x, int y){
     if(x%y == 0){
        return 2*y;
    }
    else if(y%x==0){
        return 2*x;
    }
    
        if(x>y){
            return func(x%y,y);
        }
        return func(x,y%x);
}