Advertisement
smatskevich

GCD

Oct 2nd, 2021
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main() {
  4.   int a, b;
  5.   std::cin >> a >> b;
  6.  
  7.   while (b != 0) {
  8.     int r = a % b;
  9.     a = b;
  10.     b = r;
  11.     std::cout << r << " ";
  12.   }
  13.   std::cout << std::endl;
  14.  
  15. //  for (int i = std::min(a, b); i >= 1; --i) {
  16. //    if (a % i == 0 && b % i == 0) {
  17. //      gcd = i;
  18. //      break;
  19. //    }
  20. //  }
  21.  
  22.   std::cout << a;
  23.   return 0;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement