Advertisement
TwITe

Untitled

Sep 9th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <cassert>
  2. #include <cstdint>
  3. #include <iostream>
  4.  
  5. template <class Int>
  6. Int gcd(Int a, Int b) {
  7.     if (a == 0) {
  8.         return b;
  9.     }
  10.     if (b == 0) {
  11.         return a;
  12.     }
  13.     if (a >= b) {
  14.         return gcd(a % b, b);
  15.     }
  16.     if (b >= a) {
  17.         return gcd(a, b % a);
  18.     }
  19. }
  20.  
  21. int main() {
  22.     std::int32_t a, b;
  23.     std::cin >> a >> b;
  24.     std::cout << gcd(a, b) << std::endl;
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement