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