#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007ll;
const double EPS = 1e-11;
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  if (d == 1) {
    long long ans = (long long)n * (n - 1) / 2;
    printf("%lld\n", ans);
    return 0;
  }
  n -= 2;
  long long x = d - 1;
  long long u = n / x;
  long long r = n % x;
  long long ans = 0;
  if (r > 0) {
    ans += (u + 1) + u;
    long long p = (u + 1) * (u + 1);
    long long q = u * u;
    ans += p * (r - 1) + q * (x - r - 1) + (u + 1) * u;
    p = (u + 1) * u / 2;
    q = u * (u - 1) / 2;
    ans += p * r + q * (x - r);
  } else {
    ans += u + u;
    ans += (x - 1) * u * u;
    ans += x * u * (u - 1) / 2;
  }
  printf("%lld\n", ans);
  return 0;
}
