Pagini recente » Cod sursa (job #728798) | Cod sursa (job #1743654) | Cod sursa (job #998837) | Cod sursa (job #386996) | Cod sursa (job #1758028)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int n;
int a,b;
int main()
{
ifstream be("euclid2.in");
ofstream ki("euclid2.out");
be>>n;
for(int i = 0;i<n;i++)
{
be>>a>>b;
while(a!=b)
{
if(a%b == 0)
{
a = min(a,b);
break;
}
else if(b%a == 0)
{
a = min(a,b);
break;
}
else if(a<b)
{
b-=(b/a)*a;
}
else
{
a-=(a/b)*b;
}
}
ki<<a<<"\n";
}
return 0;
}