变量"cluster"来计算c#中的阶乘

Mar*_*inS 1 .net c# variables cluster-computing factorial

试图计算一个大数的阶乘,例如1000!

static void Main(string[] args)
        {
            UInt64 fact = 1;

            for (UInt64 i = 1000; i > 0; i--)
            {
                fact = fact * i;
            }
            Console.WriteLine(fact); //returns 0, due to overflow UInt64, max fact is 56!

            Console.ReadKey();
        }
Run Code Online (Sandbox Code Playgroud)

所以我问,如果有一些方法可以将更多变量加入到集群中,那么我可以制作一个非常大的变量来存储"大"数字.

Mar*_*ers 5

你可以使用BigInteger.此类型可以存储任意大小的整数,直到内存不足为止.