Spoj GCD2 - GCD2 Solution
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- ll gcd(ll a, ll b)
- {
- if(a==0)
- return b;
- return gcd(b%a,a);
- }
- ll reduceB(ll a, string b)
- {
- ll mod=0;
- for(int i=0; i<b.size(); i++)
- mod=(mod*10+b[i]-'0')%a;
- return mod;
- }
- ll largegcd(ll a, string b)
- {
- ll num=reduceB(a,b);
- return gcd(a,num);
- }
- int main()
- {
- ll t,a;
- cin>>t;
- while(t--)
- {
- string b;
- cin>>a>>b;
- if(a==0)
- cout<<b<<endl;
- else
- cout<<largegcd(a,b)<<endl;
- }
- return 0;
- }
No comments