Advertisement
LEGEND2004

GCD short

Jul 11th, 2023
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define double long double
  6. #define pb push_back
  7.  
  8. int GCD(int a , int b){
  9.     while(a && b){
  10.         if(a > b)
  11.             a %= b;
  12.         else
  13.             b %= a;
  14.     }
  15.     return a + b;
  16. }
  17.  
  18. int gcd(int a , int b){
  19.     if(!a || !b)
  20.         return a + b;
  21.     return gcd(b , a % b);
  22. }
  23.  
  24. signed main()
  25. {
  26.     int a , b;
  27.     cin >> a >> b;
  28.     cout << gcd(a , b) << endl;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement