leetCode/src/main/java/com/leetcode/simple/ZerosOfN.java

26 lines
458 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.leetcode.simple;
/**
* @apiNote 设计一个算法计算出n阶乘中尾部零的个数
* @author zeekling
* @version 1.0
* @since 2019-12-12
*/
public class ZerosOfN{
public long trailingZeros(long n){
long tmp = 5;
long count = 0;
while (tmp <= n){
count += n / tmp;
tmp *= 5;
}
return count;
}
public static void main(String[] args){
ZerosOfN z = new ZerosOfN();
System.out.println(z.trailingZeros(11));
}
}