您如何计算使用C#大阶乘? Windows中的计算器在Win 7溢出的阶乘(3500)。作为一种编程和数学问题,我想知道你怎么能计算出更多数量的阶乘(20000,可能是)在C#。任何指针?
How can you calculate large factorials using C#? Windows calculator in Win 7 overflows at Factorial (3500). As a programming and mathematical question I am interested in knowing how you can calculate factorial of a larger number (20000, may be) in C#. Any pointers?
我刚检查了在Win 2K3一个计算的,因为我记得做在Win 2K3一个更大的阶乘。我很惊讶的事情摸索出了道路。
I just checked with a calc on Win 2k3, since I could recall doing a bigger factorial on Win 2k3. I was surprised by the way things worked out.
计算器上WIN2K3合作过,甚至大的数字。我试过!50000,我得到了一个答案,3.3473205095971448369154760940715e + 213236
Calc on Win2k3 worked with even big numbers. I tried !50000 and I got an answer, 3.3473205095971448369154760940715e+213236
这是非常快的,而我做了这一切。
It was very fast while I did all this.
这里的主要问题是不仅要找出适当的数据类型,但也有点数学。如果我尝试写一个简单的阶乘code在C#[递归或循环],表现实在是太差了。它需要多秒得到答案。如何在Windows 2K3(或XP)的钙能在不到10秒内未执行这样一个庞大的阶乘?有没有在C#中计算阶乘编程的任何其他方式?
The main question here is not only to find out the appropriate data type, but also a bit mathematical. If I try to write a simple factorial code in C# [recursive or loop], the performance is really bad. It takes multiple seconds to get an answer. How is the calc in Windows 2k3 (or XP) able to perform such a huge factorial in less than 10 seconds? Is there any other way of calculating factorial programmatically in C#?
推荐答案
有一个看的BigInteger
结构:
Have a look at the BigInteger
structure:
http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx
也许这可以帮助你实现这个功能。
Maybe this can help you implement this functionality.
$ C $的CProject具有http://www.$c$cproject.com/KB/cs/biginteger.aspx.
CodeProject has an implementation for older versions of the framework at http://www.codeproject.com/KB/cs/biginteger.aspx.
相关推荐
最新文章