fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. #define pb push_back
  7. #define rep(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
  8. #define all(v) (v).begin(),(v).end()
  9. #define S(x) scanf("%d",&(x))
  10. #define S2(x,y) scanf("%d%d",&(x),&(y))
  11. #define SL(x) scanf("%lld",&(x))
  12. #define SL2(x) scanf("%lld%lld",&(x),&(y))
  13. #define SS second
  14. #define FF first
  15. #define MOD 1000007
  16.  
  17. //int factors[100];
  18. map<long long, int> factors;
  19. int idx=0;
  20.  
  21. void findFactor(long long n){
  22. while(n%2==0){
  23. factors[2]++;
  24. n = n/2;
  25. }
  26. for(int i=3; i<=sqrt(n); i += 2){
  27. while(n%i==0){
  28. factors[i]++;
  29. n = n/i;
  30. }
  31. }
  32. if(n>2)
  33. factors[n]++;
  34. }
  35.  
  36. int main(){
  37. ios::sync_with_stdio(false);
  38. cin.tie(0);
  39. // freopen("in.txt","r",stdin);
  40.  
  41. long long n,b;
  42. cin>>n>>b;
  43.  
  44. findFactor(b);
  45. //for(auto x: factors)
  46. // cout<<x.first<<" "<<x.second<<endl;
  47. long long mp,cnt(0),mn(LONG_MAX);
  48. // for(auto x: factors){
  49. // mp = x.first;
  50. // }
  51. // cout<<mp<<endl;
  52.  
  53. for(auto x: factors){
  54. mp = x.first;
  55. cnt = 0;
  56. for(long long i=mp;n/i>=1;i = i*mp){
  57. // cout<<i<<endl;
  58. cnt += n/i;
  59. }
  60. //cout<<x.first<<" "<<cnt<<" "<<mn<<endl;
  61. cnt = cnt / x.second;
  62. mn = min(mn,cnt);
  63. }
  64.  
  65.  
  66. // map.rbegin()->first
  67. cout<<mn<<endl;
  68.  
  69.  
  70. return 0;
  71.  
  72. }
Success #stdin #stdout 0s 15240KB
stdin
1000000000000000000 1000000000000
stdout
20833333333333332