#include <bits/stdc++.h>
using namespace std;
template <typename T>
using vec = std::vector<T>;
const int inf = 1 << 30;
const long long int infll = 1LL << 62;
const double eps = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}
void solve() {
  long long int n, x, ans = 0;
  cin >> n >> x;
  while (x * 2 <= n) {
    ans += x + (n - x) + x;
    n = n - x;
  }
  if (n - x) ans += x + (n - x) * (3 * x - n) / (n - x);
  cout << ans << endl;
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();
  return 0;
}
