其他分享
首页 > 其他分享> > 【Codeforces Round #538 (Div. 2) C. Trailing Loves (or L'oeufs?)】 分解质因数

【Codeforces Round #538 (Div. 2) C. Trailing Loves (or L'oeufs?)】 分解质因数

作者:互联网


C. Trailing Loves (or L’oeufs?)

题意

n!n!n!在b进制下末尾有多少个000
1101018,2b10121 \leq 10 \leq 10^{18},2 \leq b \leq 10^{12}1≤10≤1018,2≤b≤1012

做法

这道题我们首先考虑101010进制,那就是看n!n!n!能够整除555多少次和整除222多少次。取个minminmin即是答案,这道题做法类似,我们只需要先对bbb进行分解质因数,对每个质因数统计在bbb中出现次数cntcntcnt和在nn!n!中出现次数mmm,最后对所有的m/cntm/cntm/cnt取minminmin即可

代码

#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
ll solve(ll a,ll b)
{
    if(a==0) return 0;
    return a/b+solve(a/b,b);
}
int main()
{
    ll a,b;
    scanf("%lld%lld",&a,&b);
    ll ans=LL_INF;
    for(ll i=2;i*i<=b;i++)
    {
        if(b%i==0)
        {
            int cnt=0;
            while(b%i==0)
            {
                cnt++;
                b/=i;
            }
            ans=min(ans,solve(a,i)/cnt);
        }
    }
    if(b>1)  ans=min(ans,solve(a,b));
    printf("%lld\n",ans);
    return 0;
}

标签:10,return,ll,Codeforces,leq,oeufs,Loves,ans,include
来源: https://blog.csdn.net/qq_38891827/article/details/88072414