fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // Числа Белла
  6. int n, p;
  7. while (cin >> n >> p) {
  8. int k = 0;
  9. for (int i = 1; i <= n; i++) {
  10. int fact = i;
  11. while (fact) {
  12. fact /= p;
  13. k += fact;
  14. }
  15. }
  16. cout << k << "\n";
  17. }
  18. return 0;
  19. }
Success #stdin #stdout 0s 4320KB
stdin
1 5
3 2
4 2
4 3
10000 3
stdout
0
2
5
2
24962375