#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, X;
  cin >> N >> X;
  ll ans = 0;
  ans += N;
  if (3 * X == N) {
    ans += N;
    cout << ans << "\n";
    return 0;
  }
  N -= X;
  while (X > 0) {
    if ((N % X) == 0) {
      ans += (N + X);
      break;
    }
    ans += (2 * X);
    N -= X;
    if (X > N) {
      ll tmp = X;
      X = N;
      N = tmp;
    }
  }
  cout << X << "\n";
  cout << ans << "\n";
  return 0;
}
