标签:min codeforce sqrt code nbsp rail def print ufs
大意: 求n!在b进制下末尾0的个数
等价于求n!中有多少因子b, 素数分解一下, 再对求出所有素数的最小因子数就好了
ll n, b; vector<pli> A, res; void factor(ll x) { int mx = sqrt(x+0.5); REP(i,2,mx) if (x%i==0) { int t = 0; while (x%i==0) x/=i,++t; A.pb(pli(i,t)); } if (x>1) A.pb(pli(x,1)); } int main() { cin>>n>>b; factor(b); int sz = A.size(); ll ans = 1e18; REP(i,0,sz-1) { ll t = 0, num = n/A[i].x; while (num) t+=num, num/=A[i].x; ans = min(ans, t/A[i].y); } printf("%lld\n", ans); }
Trailing Loves (or L'oeufs?) CodeForces - 1114C (数论)
标签:min codeforce sqrt code nbsp rail def print ufs
原文地址:https://www.cnblogs.com/uid001/p/10507583.html