#include <bits/stdc++.h>
using namespace std;
const int INF = 0x6fffffff;
const int MINF = 0x80000000;
const long long mod = 100003;
const int cons = 100001;
const double pi = 3.141592653589793;
int main() {
  double n, x;
  cin >> n >> x;
  double ans = n - x;
  double t = x;
  while (t > 0.00001) {
    double num = floor(n / t);
    ans += (2 * num - 1) * t;
    x = n - floor(n / t) * t;
    n = t;
    t = x;
  }
  printf("%lf\n", ans);
  return 0;
}
