Problem Link: CHOCOWAR

Problem:

Ram and Shyam are fighting over chocolates. Ram has X chocolates, while Shyam has Y.

Whoever has lesser number of chocolates eats as many chocolates as he has from the other’s collection. This eatfest war continues till either they have the same number of chocolates, or atleast one of them is left with no chocolates. Can you help me predict the total no of chocolates they’ll be left with at the end of their war?

**Input:**

First line will contain T, number of testcases. Then the testcases follow.

Each testcase contains of a single line of input, which contains two integers X,Y, the no of chocolates Meliodas and Ban have, respectively.

**OUTPUT:**

For each testcase, output in a single line the no of chocolates that remain after Ban and Meliodas stop fighting.

**Constraints:**

1 ≤ T ≤ 10000

0 ≤ X, Y ≤ 10^9

**Sample Input:**

3

5 3

10 10

4 8

**Sample Output:**

2

20

8

**Explanation**

Denoting Ram as R, Shyam as S

Testcase 1:

R=5, S=3

Ram eates 3 chocolates of Shyam.

R=2, S=3

Shyam eats 2 chocolates of Ram.

R=2, S=1

Ram eates 1 chocolate of Shyam.

R=1, S=1

Since they have the same no of candies, they stop quarreling.

Total candies left: 2

**Solution:**

#include"bits/stdc++.h"

using namespace std;

int sum(int x,int y)

{

while(x!=0 || y!=0)

{

if(x==0)

{

return y;

}

else if(y==0)

return x;

else if(x==y)

{

return x+y;

}

else if(x>y)

{

int g=x-y;

x=g;

}

else

{

int h=y-x;

y=h;

}

}

return x+y;

}

int main() {

// your code goes here

int t,x,y;

cin>>t;

for(int i=0;i<t;i++)

{

cin>>x>>y;

int a=sum(x,y);

cout<<a<<endl;

}

return 0;

}