#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a;
  long long b;
  long long ret = 0;
  cin >> a >> b;
  ret += a;
  a -= b;
  cout << ret << endl;
  while (a) {
    long long r = b % a;
    ret += (b / a) * a * 2;
    if (r == 0) {
      ret -= a;
    }
    b = a;
    a = r;
  }
  cout << ret << endl;
}
