Data type in C # for finding factorial

What is the largest data type in C # or what data type should I use to find factorial 1619. I tried ulong and uint64, but they truncated my answer.

+4
source share
1 answer

take a look https://msdn.microsoft.com/en-us/library/system.numerics.biginteger%28v=vs.110%29.aspx

Is BigInteger not very fast, but for large numbers you can calculate

Here is a simple example from MSDN

string positiveString = "91389681247993671255432112000000";
string negativeString = "-90315837410896312071002088037140000";
BigInteger posBigInt = 0;
BigInteger negBigInt = 0;

    try 
    {
         posBigInt = BigInteger.Parse(positiveString);
         Console.WriteLine(posBigInt);
    }
    catch (FormatException)
    {
         Console.WriteLine("Unable to convert the string '{0}' to a BigInteger value.", positiveString);
    }

I try to use my own example and it works

string positiveString = "91389681247993671255432112000000";
string negativeString = "-90315837410896312071002088037140000";
BigInteger b = BigInteger.Parse(positiveString);
BigInteger c = BigInteger.Parse(positiveString);
BigInteger d = b * c;

System.Console.WriteLine(d);
System.Console.ReadLine();

// result 835207383860988607360648144841987935757186784078054400000000000
+1
source

Source: https://habr.com/ru/post/1626766/


All Articles