import java.util.Scanner;
public class Main {
public static void main
(String[] args
) { Scanner scanner
= new Scanner
(System.
in); int n, p;
while(scanner.hasNextInt()) {
n = scanner.nextInt();
p = scanner.nextInt();
int k = 0;
for (int i = 1; i <= n; i++) {
int fact = i;
while (fact > 0) {
fact /= p;
k += fact;
}
}
}
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwpwdWJsaWMgY2xhc3MgTWFpbiB7CiAJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHsKICAgCQlTY2FubmVyIHNjYW5uZXIgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwogICAJCWludCBuLCBwOwogICAJCXdoaWxlKHNjYW5uZXIuaGFzTmV4dEludCgpKSB7CiAgIAkJCW4gPSBzY2FubmVyLm5leHRJbnQoKTsKICAgCQkJcCA9IHNjYW5uZXIubmV4dEludCgpOwogICAJCQlpbnQgayA9IDA7CiAgIAkJCWZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAJCQkJaW50IGZhY3QgPSBpOwogICAJCQkJd2hpbGUgKGZhY3QgPiAwKSB7CiAgIAkJCQkJZmFjdCAvPSBwOwogICAJCQkJCWsgKz0gZmFjdDsKICAgCQkJCX0KICAgCQkJfQogICAJCQlTeXN0ZW0ub3V0LnByaW50bG4oayk7CiAgIAkJfQogICAJfQp9