Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int GCD(int a, int b) {
- if (a == 0 || b == 0) throw std::runtime_error("Zero params for GCD");
- // Алгоритм Евклида
- while (true) {
- int r = a % b;
- if (r == 0) return b;
- a = b;
- b = r;
- }
- }
- int main() {
- int a = 0, b = 0;
- std::cin >> a >> b;
- std::cout << GCD(a, b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement