Skip to content

Latest commit

 

History

History

FactorialTrailingZeroes172

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Given an integer n, return the number of trailing zeroes in n!.

#####Note: Your solution should be in logarithmic time complexity.

思路

0由2*5实现 因此,n以内因子2的个数及因子5的个数决定了结果中0的个数 而5的个数比2少 因此,最终结果由因子5的个数决定 n以内因子5的个数为循环除以5求和,直到n为0

如 51 则 51 / 5 = 10 10 / 5 = 2 2 / 5 = 0 故51内所有的因子5的个数为 10 + 2 + 0 = 12 分别为 一个5因子 5 10 15 20 25 30 35 40 45 50 一个25因子 25 50

分别为: 5,10,1

又如1001 则 1001 / 5 = 200 200 / 5 = 40 40 / 5 = 8 8 / 5 = 1 1 / 5 = 0 故 1001内所有的因子5的个数为 200+40+8+1+0 = 249 个