Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7. typedef unsigned int ui;
  8.  
  9. ui k, n;
  10.  
  11. ui minn(ui a, ui b) {
  12.     if (a < b)
  13.         return a;
  14.     return b;
  15. }
  16.  
  17. int main() {
  18.     //freopen("input.txt", "r", stdin);
  19.     //freopen("output.txt", "w", stdout);
  20.     cin >> n >> k;
  21.  
  22.     ui t = k, ch = 2, ans = 10000000000;
  23.     while (t > 1) {
  24.         ui pk = 0, pn = 0; ll nn = ch;
  25.     if (t % ch == 0) {
  26.             while (t % ch == 0) {
  27.                 t /= ch;
  28.                 ++pk;
  29.             }
  30.             while (nn <= n) {
  31.                 pn += n / nn;
  32.                 nn *= ch;
  33.             }
  34.             ans = minn(pn / pk, ans);
  35.         }
  36.         ++ch;
  37.     }
  38.  
  39.     cout << ans << endl;
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement