The main topic: let n! The number of bits in the base and the consecutive number of the end 0.
Title Analysis: A M-bit of the B-number N, the minimum is b^ (m-1), the maximum is not more than b^m, that is b^ (m-1) ≤n<b^m. Solution inequality, get Log10 (n)/log10 (b) <m≤log10 (n)/log10 (b) +1.
As for the number of 0, the n! Decomposition of factorization, factorization to base decomposition. See n! The number of base that can be pooled in the mass factor. The number of base that can be pooled is the number of the end 0. Set n! The set of common factorization with base is S1. The set of the mass factor of base is S2, then the number of the end 0 is min (S1 (S2 (i))/s2 (i)).
In fact, this problem is nothing more than the integration of multiple algorithms. Sieve prime number + sieve large prime number + decomposition factorization.
The code is as follows:
# include<iostream># include<cstdio># include<cmath># include<map># include<cstring># include<algorithm>using namespacestd;Const intn=1<< -;Doublea[n+ -];intpri[ Max],mark[ -];map<int,int>m[805];voidinit () {a[1]=LOG10 (1.0); for(intI=2; i<=n;++i) a[i]=a[i-1]+log10 (i); for(intI=2; i<= -;++i) { intn=i; intA=2; while(a*a<=N) { while(n%a==0){ ++M[i][a]; N/=A; } ++A; } if(n>1) ++M[i][n]; } pri[0]=0; memset (Mark,0,sizeof(Mark)); for(intI=2; i<= -;++i) { if(!Mark[i]) pri[++pri[0]]=i; for(intj=1; j<=pri[0]&&i*pri[j]<= -;++j) {Mark[i*pri[j]]=1; if(i%pri[j]==0) Break; } }}intFintNintk) {Map<int,int>MP; for(intI=2; i<=n;++i) { intn=i; for(intj=1; j<=pri[0]&&pri[j]<=k;++j) { while(n%pri[j]==0){ ++Mp[pri[j]]; N/=Pri[j]; }}} Map<int,int>:: Iterator it; intans=1<< -; for(It=m[k].begin (); It!=m[k].end (); + +it) {ans=min (ans,mp[it->first]/(it->second)); } returnans;}intGintNintk) { DoubleANS=A[N]/LOG10 (k) +1.0; return(int) ans;intMain () {init (); intn,k; while(SCANF ("%d%d", &n,&k)! =EOF) {printf ("%d%d\n", F (n,k), G (n,k)); } return 0;}
UVA-10061 how many Zero's and how many digits? Number theory