Title Link: http://lightoj.com/volume_showproblem.php?problem=1138
Test instructions: give you a number n, then find a minimum number x, so that the end of x! has n 0; if there is no output impossible
Can be used to find the result, the focus is to find a number of the factorial of the end contains 0 of the number, must be related to the number of factors 5 and 2, the factor of 2 is significantly more than 5, so we only need a number of factorial factor in a total of how many 5 can be;
ll Find (ll x) { 0; while (x) { + = x/5; 5 ; } return ans;}
For example 125! 125/5 = 25; So the item with 5 in 125! is 25*5+24*5+23*5+...+3*5+2*5+1*5 = 25!*5
So 125! At the end of the 25+5+1 = 31 0;
#include <stdio.h>#include<string.h>#include<algorithm>#include<math.h>typedefLong LongLL;#defineN 1000001using namespacestd;Const DoubleEPS = 1e-6; ll Find (ll x) {ll ans=0; while(x) {ans+ = x/5; X/=5; } returnans;}intMain () {intT, T =1, N; scanf ("%d", &T); while(T--) {scanf ("%d", &N); LL ans=0, L =2, R =1000000000; while(L <=R) {LL Mid= (l+r)/2; LL ret=Find (Mid); if(ret = =N) Ans=Mid; if(Ret >=N) R= Mid-1; ElseL= Mid +1; } if(ans = =0) printf ("Case %d:impossible\n", t++); Elseprintf ("Case %d:%lld\n", t++, ans); } return 0;}
View Code
Lightoj 1138-trailing Zeroes (III) factorial end 0 Number & two points