Spoj GCD2 - GCD2 Solution

   ///La ilaha illellahu muhammadur rasulullah

///******Bismillahir-Rahmanir-Rahim******///

///Abul Hasnat  Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    1. #include <bits/stdc++.h>
    2. using namespace std;
    3. typedef long long int ll;
    4. ll gcd(ll a, ll b)
    5. {
    6. if(a==0)
    7. return b;
    8. return gcd(b%a,a);
    9. }
    10. ll reduceB(ll a, string b)
    11. {
    12. ll mod=0;
    13. for(int i=0; i<b.size(); i++)
    14. mod=(mod*10+b[i]-'0')%a;
    15.  
    16. return mod;
    17. }
    18. ll largegcd(ll a, string b)
    19. {
    20. ll num=reduceB(a,b);
    21. return gcd(a,num);
    22. }
    23. int main()
    24. {
    25. ll t,a;
    26. cin>>t;
    27. while(t--)
    28. {
    29. string b;
    30. cin>>a>>b;
    31. if(a==0)
    32. cout<<b<<endl;
    33. else
    34. cout<<largegcd(a,b)<<endl;
    35. }
    36. return 0;
    37. }
    38.  

    No comments

    Most View Post

    Recent post

    Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

        Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

    Powered by Blogger.