Advertisement
Josif_tepe

Untitled

Dec 26th, 2022
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <cstring>
  5. #include <queue>
  6. #include <algorithm>
  7. using namespace std;
  8. int gcd(int a, int b) { // bitno e A da e pogolemiot broj, a B da e pomaliot broj
  9.     if(a < b) {
  10.         swap(a, b);
  11.     }
  12.     while(b != 0) {
  13.         int tmp = a;
  14.         a = b;
  15.         b = tmp % b;
  16.     }
  17.     return a;
  18. }
  19. int main() {
  20.     cout << gcd(9, 40) << endl;
  21.     cout << gcd(50, 100) << endl;
  22.     return 0;
  23. }
  24. /*
  25.  10 9
  26.  1 6
  27.  1 9
  28.  1 10
  29.  2 6
  30.  2 7
  31.  3 7
  32.  4 8
  33.  4 9
  34.  5 10
  35.  */
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement