#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  while (~scanf("%I64d%I64d", &a, &b)) {
    if (a == 0 || b == 0) break;
    while (b >= 2 * a || a >= 2 * b) {
      if (a == 0 || b == 0) break;
      if (a >= 2 * b)
        a = a % (2 * b);
      else if (b >= 2 * a)
        b = b % (2 * a);
    }
    printf("%I64d %I64d\n", a, b);
  }
  return 0;
}
