#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x;
  cin >> n >> x;
  if (n % x != 0) {
    cout << n + 2 * x + n * n - 3 * x * n + 2 * x * x << endl;
  } else {
    cout << n + 2 * x * ((n / x) - 1) << endl;
  }
}
