关于阶乘的逻辑问题
我有一个问题,无法独自解决。我的老师今天给了我一项逻辑任务,我相信你能帮助我。
如何计算 factorial(41) 末尾的零个数。 (纸上) 我知道这与编程无关,但我确信程序员可以帮助我。
提前致谢。
I have a problem and can't solve it alone. My teacher gives me one logic task today, and i'm sure you can help me.
How can I count the number of zeroes at the end of factorial(41). (on paper)
I understand that it has nothing to do with programing, but I'm sure programers can help me.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你知道这个窍门,你甚至不需要纸。末尾零的数量是它能被 10 整除的次数。 。 。就质因数分解而言,这是能被 5 整除的次数和能被 2 整除的次数的最小值(因为我们需要 2 和 5 的一个因数来生成一个因数)系数 10)。但对于阶乘,我们将所有小于或等于 41 的因数都包括在内,因此我们得到的 2 因数将多于 5 因数。因此,我们只需要关心 5 的因数有多少个。
计算小于或等于 41 且能被 5 整除的数字:
5,10,15,20,25,30,35,40
一共有 8 个,但不要忘记 25 给了我们一个额外的因数 5,因为它可以被 5 整除两次。所以一共是 5 的 9 个因数(也就是 10 的 9 个因数)。
If you know the trick, you don't even need paper. The number of zeros at the end is how many times it's divisible by 10 . . . in terms of the prime factorization, this is the minimum of the number of times it's divisible by 5 and the number of times it's divisible by 2 (since we need one factor of both 2 and 5 to make a factor of 10). But with factorial we're including every factor less than or equal to 41, so we'll get a lot more factors of 2 than factors of 5. So we only need to worry about how many factors of 5 there are.
So count the numbers that are less than or equal to 41 and divisible by 5:
5,10,15,20,25,30,35,40
There's 8 of them, but don't forget that 25 gives us an extra factor of 5, since it's divisible by 5 twice. So 9 factors of 5 (and thus 9 factors of 10) in all.
在你的情况下 n = 41
请参阅下面的评论
in your case n = 41
See comments below