Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define maxn 90000
- #define ll long long
- int primes[maxn];
- int freqb[maxn],freqn[maxn];
- ll n,b,aux,aux2,nr=2,ans=9999999999,sol2;
- int i,j,cnt,l;
- int main()
- {
- cin>>n>>b;
- aux2=b;
- while(b>1){
- if(b%nr==0){
- primes[++cnt]=nr;
- while(b%nr==0){
- freqb[cnt]++;
- b/=nr;
- }
- }
- nr++;
- }
- for(l=1;l<=cnt;l++){
- for(i=primes[l];i<=n;i+=primes[l])
- if(!viz[i]){
- aux=i;
- while(aux%aux2==0){
- aux/=aux2;
- sol2++;
- }
- for(j=1;j<=cnt&&aux>1;++j)
- while(aux%primes[j]==0){
- ++freqn[j];
- aux/=primes[j];
- }
- }
- }
- for(i=1;i<=cnt;++i)
- if(ans>(freqn[i]/freqb[i]))
- ans=freqn[i]/freqb[i];
- cout<<ans+sol2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement