Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.    
  6. ll reduceB(ll a, string b) {
  7.     ll mod = 0;
  8.     for (int i=0; i<b.length(); i++)
  9.         mod = (mod*10 + b[i] - '0')%a;
  10.  
  11.     return mod;
  12. }
  13.    
  14. ll gcdLarge(ll a, string b) {
  15.     ll num = reduceB(a, b);
  16.    return __gcd(a, num);
  17. }
  18.  
  19.  
  20. int main() {  
  21.     int T;
  22.     cin >> T;
  23.     while(T--){
  24.         ll a;
  25.         string b;
  26.         cin >> a >> b;  
  27.         cout << gcdLarge(a, b) << endl;
  28.     }  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement