#include <bits/stdc++.h>
using namespace std;
void boost() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 1e6;
const int inf = 1e9 + 7;
long long n, x;
int main() {
  boost();
  cin >> n >> x;
  cout << x / (n - x - (n - x) / x * x) * (n - x - (n - x) / x * x) +
              (n - x - (n - x) / x * x) + n + (n - x) / x * x * 2;
}
