GCD2 - GCD2
#include <iostream>
#include <string>
using namespace std;
long long int gcd(long long int a, long long int b)
{
if(a == 0)
return b;
return gcd(b % a, a);
}
long long int reduceNumber(long long int a, string s)
{
long long int r = 0;
for(int i = 0; i < s.size(); i++)
{
r = r * 10 + (s[i] - '0');
r = r % a;
}
return r;
}
int main()
{
int n;
cin >> n;
long long int a, b;
string s;
while(n--)
{
cin >> a;
cin >> s;
if(!a)
{
cout << s << endl;
continue;
}
b = reduceNumber(a, s);
cout << gcd(a, b) << endl;
}
return 0;
}
Comments
Post a Comment