Advertisement
MaxObznyi

gcd

Jun 11th, 2022
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int gcd(int a, int b) {
  7. while (a != 0 && b != 0) {
  8. if (a > b)
  9. a %= b;
  10. else
  11. b %= a;
  12. }
  13. return a + b;
  14. }
  15.  
  16. int main()
  17. {
  18. int a, b;
  19. cin >> a >> b;
  20. cout << gcd(a, b) << ' ' << __gcd(a, b);
  21. return 0;
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement