#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, i;
  scanf("%d %d", &n, &x);
  int a = n, b = x, sum = 0;
  sum += n;
  a = n - x;
  while (a != 0 && b != 0) {
    printf("%d %d\n", a, b);
    if (a < b) swap(a, b);
    sum += (a / b) * 2 * b;
    a = a % b;
    printf("%d %d\n", a, b);
  }
  printf("%d", sum - 1);
}
