Advertisement
Alhiris

NICE TRY

Feb 10th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define maxn 90000
  4. #define ll long long
  5.  
  6. int primes[maxn];
  7. int freqb[maxn],freqn[maxn];
  8. ll n,b,aux,aux2,nr=2,ans=9999999999,sol2;
  9. int i,j,cnt,l;
  10.  
  11. int main()
  12. {
  13.     cin>>n>>b;
  14.     aux2=b;
  15.     while(b>1){
  16.         if(b%nr==0){
  17.             primes[++cnt]=nr;
  18.             while(b%nr==0){
  19.                 freqb[cnt]++;
  20.                 b/=nr;
  21.             }
  22.         }
  23.         nr++;
  24.     }
  25.     for(l=1;l<=cnt;l++){
  26.         for(i=primes[l];i<=n;i+=primes[l])
  27.             if(!viz[i]){
  28.             aux=i;
  29.             while(aux%aux2==0){
  30.                 aux/=aux2;
  31.                 sol2++;
  32.             }
  33.             for(j=1;j<=cnt&&aux>1;++j)
  34.                 while(aux%primes[j]==0){
  35.                     ++freqn[j];
  36.                     aux/=primes[j];
  37.                 }
  38.         }
  39.     }
  40.     for(i=1;i<=cnt;++i)
  41.         if(ans>(freqn[i]/freqb[i]))
  42.             ans=freqn[i]/freqb[i];
  43.     cout<<ans+sol2;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement