求阶乘N!末尾0的个数

博客讲述了如何计算阶乘N!末尾0的个数,从初中的简单方法到考虑溢出问题,再到使用高精度模拟和大学生解法的优化过程。博主通过不断改进算法,最终得出一个高效且适用于大数阶乘的解决方案,该算法具有较低的时间复杂度。
摘要由CSDN通过智能技术生成

POJ上有这个题目。http://poj.org/problem?id=1401。去掉一大堆没有用的信息,POJ的描述如下:

For example, they defined the function Z. For any positive integer N, Z(N) is the number of zeros at the end of the decimal form of number N!. They noticed that this function never decreases. If we have two numbers N1 < N2, then Z(N1) <= Z(N2). It is because we can never "lose" any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program that can determine its value efficiently.

大概意思就是求N!的末尾0的个数。比如:5! = 120;则末尾0的个数为1.

 

呵呵,这个题目还不简单么。看初中生的解法:

呵呵,代码写完了,那就测试呗。下面是我给的测试数据:

0
0

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值