SAC E#1 - 一道中档题 Factorial

#include <cstdio>
#include <iostream>
#define regint register int
using namespace std;
long long n,k,p[1000010],cnt,sum[1000010],ans=1e18;

long long check(long long n,long long k){
    long long cnt=0;
    for(n/=k;n;n/=k)cnt+=n;
    return cnt;
}

int main(){
    while(scanf("%lld%lld",&n,&k) && n!=0){
        for(int i=2;i*i<=k;i++){
            long long cnt=0;
            while(k%i==0){cnt++; k/=i;}
            if(cnt)ans=min(ans,check(n,i)/cnt);
        }
        if(k>1)ans=min(ans,check(n,k));
        printf("%lld\n",ans);
        return 0;
    }
}

  

posted @ 2017-10-16 13:27  wqtnb_tql_qwq_%%%  阅读(114)  评论(0编辑  收藏  举报