function calculateBellNumbers(n, p) {
let k = 0;
for (let i = 1; i <= n; i++) {
let fact = i;
while (fact) {
fact = Math.floor(fact / p);
k += fact;
}
}
return k;
}
ZnVuY3Rpb24gY2FsY3VsYXRlQmVsbE51bWJlcnMobiwgcCkgewogICAgbGV0IGsgPSAwOwogICAgZm9yIChsZXQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CiAgICAgICAgbGV0IGZhY3QgPSBpOwogICAgICAgIHdoaWxlIChmYWN0KSB7CiAgICAgICAgICAgIGZhY3QgPSBNYXRoLmZsb29yKGZhY3QgLyBwKTsKICAgICAgICAgICAgayArPSBmYWN0OwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBrOwp9Cg==