UVA-10061 how many Zero's and how many digits? Number theory

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.