#include <iostream>
using namespace std;
int main() {
// Числа Белла
int n, p;
while (cin >> n >> p) {
int k = 0;
for (int i = 1; i <= n; i++) {
int fact = i;
while (fact) {
fact /= p;
k += fact;
}
}
cout << k << "\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CgkvLyDQp9C40YHQu9CwINCR0LXQu9C70LAKCWludCBuLCBwOwoJd2hpbGUgKGNpbiA+PiBuID4+IHApIHsKCQlpbnQgayA9IDA7CgkJZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CgkJCWludCBmYWN0ID0gaTsKCQkJd2hpbGUgKGZhY3QpIHsKCQkJCWZhY3QgLz0gcDsKCQkJCWsgKz0gZmFjdDsKCQkJfQoJCX0KCQljb3V0IDw8IGsgPDwgIlxuIjsKCX0KCXJldHVybiAwOwp9