本文主要是介绍Trailing Loves (or L'oeufs?) CodeForces - 1114C,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://codeforces.com/problemset/problem/1114/C
将b素因子拆分 形如b=(a1^p1)*(a2^p2)*...*(ak^pk)
凑出一个尾0 就需要p1个a1 p2个a2...pk个ak 然后看n能提供多少 取最小即可
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=0x3f3f3f3f3f3f3f3f;int main()
{ll n,b,i,lim,sum,val,tmp,ans;scanf("%lld%lld",&n,&b);ans=N;for(i=2;i*i<=b;i++){if(b%i==0){lim=0;while(b%i==0){b/=i;lim++;}sum=0,val=1,tmp=i;while(1){if(n/val<tmp) break;val*=tmp;sum+=n/val;}ans=min(ans,sum/lim);}}if(b!=1){sum=0,val=1,tmp=b;while(1){if(n/val<tmp) break;val*=tmp;sum+=n/val;}ans=min(ans,sum);}printf("%lld\n",ans);return 0;
}//1000000000000000000 97
这篇关于Trailing Loves (or L'oeufs?) CodeForces - 1114C的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!