阶乘的大量总和 [英] Sum of factorials for large numbers
问题描述
我要计算的N个数字的总和!
I want to calculate the sum of digits of N!.
我想这样做的N个真正的大值,比如说N(1500)。我没有使用.NET 4.0。我不能使用BigInteger类来解决这个问题。
I want to do this for really large values of N, say N(1500). I am not using .NET 4.0. I cannot use the BigInteger class to solve this.
这可以通过一些其他的算法或程序解决了吗?请大家帮帮忙。
Can this be solved by some other algorithm or procedure? Please help.
我想要做一些这样的事<一href="http://stackoverflow.com/questions/1966077/calculate-the-factorial-of-an-arbitrarily-large-number-showing-all-the-digits">Calculate一个任意大的数的阶乘,显示所有的数字但在C#。但是我无法解决。
I want to do some thing like this Calculate the factorial of an arbitrarily large number, showing all the digits but in C#. However I am unable to solve.
推荐答案
有,你可以使用任何执行你选择两个性能的捷径。
There are two performance shortcuts that you can use for whatever implementation you choose.
- 从数字砍掉任何零。
- 如果数字是5整除的n次方,10的n次方。 把它
以这种方式,
16*15*14*13*12*11*10*9*8*7*6*5*4*3*2 = 20,922,789,888,000
//-->
16*1.5*14*13*12*11*1*9*8*7*6*0.5*4*3*2 = 20,922,789,888 //Sum of 63
另外,感觉应该有一定的算法没有恢复到计算这一切了。将18!的数字的总和是:
Also, it feels like there should be some algorithm without reverting to calculating it all out. Going to 18!, the sums of the digits are:
2,6,6,3,9,9,9,27,27,36,27,27,45,45,63,63,63
//the sums of the resulting digits are:
2,6,6,3,9,9,9,9,9,9,9,9,9,9,9,9,9
和值得注意的是,的1500数字的总和!是16749(的总和,其数字是27)
and notably, the sum of the digits of 1500! is 16749 (the sum of whose digits are 27)
这篇关于阶乘的大量总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!