Number of XDU1019 factorial factors

Source: Internet
Author: User

Test instructions is to let you ask for a minimum of N, so that n! has M 0,n factorial in 2 of the factor is far more than 5 of the number of factors, so we count 5 of the number of it will know that there are several 0, for a number of mid, mid! 5 of the number of factors is MID/5 + MID/25 + mid/5^3 + ... You can see that the larger the mid-mid!, the greater the number of 5, so we can answer the two points, the code is as follows:

#include <cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespaceStd;typedefLong LongLL;intM;intCheck (LL mid)//The number of 5 in the factorial of mid{LL a=5; intres =0;  while(A <=mid) {res+ = Mid/A; A*=5; }    returnRes;}intMain () {intT; CIN>>u;  while(t--) {cin>>l; LL L=1, r=1000000000; LL Res= -1;  while(L <=r) {LL mid= (l+r)/2; intTP =Check (mid); if(TP = =M) {res=mid; R= mid-1; }            Else if(TP > M) r = mid-1; ElseL = mid +1; }        if(res = =-1) cout<<"No solution\n"; Elsecout<<res<<Endl; }    return 0;}

Number of XDU1019 factorial factors

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.