Please refer to the topic Description: ZOJ ACM 2022
1) Difficulty analysis
Is the extension of the large number factorial. If you want to calculate the number of digits in the end 0, the time efficiency is far from satisfying the requirement of 2 seconds.
2) Workaround
The result is calculated by the law. Sets the number of digits at the end of the result of calculating the factorial of N to 0. where n=n* (N-1) *....*i*....*1, Mantissa is 0 of the mantissa is zeronumber.
First of all, only when I is a multiple of 5, the i*2 must be a single digit of 0;
Second, when I is 5 K-square, i* (2 of the K-th square) = (5*2) of the K-square, so inevitably at the end of the K 0. Because it is a factorial operation, 5 of the K-square, it is bound to encounter 2 K-square.
With the above-mentioned two points, we can conclude as follows:
N is 5 l times = = "has l a 5 and 2 multiplied by = =" has l 10 = = "Zeronumber = l;
N is 5 k times the M = = "Zeronumber increase (k-1) *m. (Note: Because 5 of the two is increased by 2 0, but because the previous calculation of 5 times times, has been increased once 1, so only need to add 1 more times, and so on.) )
3) AC Source code
public class Main {public static void main (string[] args) {//TODO auto-generated method Stubjava.util.Scanner Scanner = n EW Java.util.Scanner (system.in); int linenum = Integer.parseint (Scanner.nextline ()); for (int lineindex = 0; lineindex < LineNum; lineindex++) {Long n = Long.parselong (Scanner.nextline ()); System.out.println (CALC_V2 (n));}} public static long Calc_v2 (long N) {long zeronumber = 0;for (int i=1;i<20;i++) { //The reason for setting 20 here is that POW (5,20) > The maximum value of n in the title is 1000000000, and the actual setting 20 has a surplus. Long BigNumber = (long) Math.pow (5, I); zeronumber+= N/bignumber;} return zeronumber;}}