#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, x;
  cin >> n >> x;
  long long ans = 0;
  x = min(x, n - x);
  long long h = n - x, c = x, l = x;
  while (1) {
    if (h != 0 && l > 0) {
      if (h < l) {
        l--;
        continue;
      }
      ans += 3 * l * (h / l);
      h = h % l;
      c = l;
    } else if (c != 0) {
      ans += 3 * c * (x - c);
      c = 0;
    }
    l--;
    if (l <= 0 && c == 0) break;
  }
  cout << ans << endl;
}
