Advertisement
Emiliatan

e793-1

Dec 30th, 2019
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. /* e793 - 1 */
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. using int64 = long long;
  7.  
  8. class A;
  9.  
  10. A* arr[2];
  11.  
  12. class A
  13. {
  14. public:
  15.     virtual int64 gcd(int64 a, int64 b)
  16.     {
  17.         return a;
  18.     }
  19. };
  20.  
  21. class B : public A
  22. {
  23. public:
  24.     virtual int64 gcd(int64 a, int64 b)
  25.     {
  26.         return arr[!!(a % b)]->gcd(b, a % b);
  27.     }
  28. };
  29.  
  30. int64 gcd_sol(int64 X, int64 Y)
  31. {
  32.     A a;
  33.     B b;
  34.     arr[!!!Y] = &a;
  35.     arr[!!Y] = &b;
  36.  
  37.     int64 value = arr[1]->gcd(X, Y);
  38.  
  39.     return value;
  40. }
  41.  
  42. int main()
  43. {
  44.     int64 X, Y;
  45.  
  46.     while (scanf("%lld %lld", &X, &Y), X || Y)
  47.     {
  48.         printf("%lld\n", gcd_sol(X, Y));
  49.     }
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement