#include using namespace std; typedef long long ll; signed main(){ ll N, M; cin >> N >> M; N = N / 1000; N %= M; cout << N * ( N - 1 ) / 2 << endl; return 0; }