Last active
August 29, 2015 14:22
-
-
Save sukeesh/f822e1d1e7097bfa9494 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Author | |
-Sukeesh | |
*/ | |
#include<iostream> | |
#include<algorithm> | |
using namespace std; | |
string str; | |
long long rem(long long x) | |
{ | |
long long i,p=0; | |
for(i=0;i<str.size()-1;i++) | |
{ | |
p=(p*10+str[i]-'0')%x; | |
} | |
p=(p*10+(str[str.size()-1]-'0'))%x; | |
return p%x; | |
} | |
int main() | |
{ | |
ios::sync_with_stdio(false); | |
long long t; | |
cin>>t; | |
while(t--) | |
{ | |
long long a,p; | |
cin>>a>>str; | |
if(a==0) | |
{ | |
cout<<str<<"\n"; | |
goto hell; | |
} | |
p=rem(a); | |
if(p==0) | |
{ | |
cout<<a<<"\n"; | |
goto hell; | |
} | |
cout<<(__gcd(a,p))<<"\n"; | |
hell:; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment