N的阶乘,N大于等于200[复制]

时间:2022-02-02 16:49:09

This question already has an answer here:

这个问题已经有了答案:

Is there any way to calculate the factorial of N, where N>200.Is there something like Bigdata in c++.Since even a long variable cannot store such a big number.can you please tell me any approach to deal with such big number problems????

有没有办法计算N的阶乘,N>200。在c++中是否有类似Bigdata的东西。因为即使是一个很长的变量也不能存储这么大的数字。你能告诉我处理这么大的数字问题的方法吗?

2 个解决方案

#1


1  

int or long types are not big enough for the values you're talking about.

int或long类型对于您所讨论的值来说不够大。

34! = 295232799039604140847618609643520000000

34 != 295232799039604140847618609643520000000

This barely fits into 128 bits. If your compiler supports a 128-bit number type, you can use it to calculate factorials up to 34. If not, or if you need anything larger, you will need to use some kind of bignum library.

这几乎不适合128位。如果您的编译器支持一个128位的数字类型,您可以使用它来计算多达34的阶乘。如果没有,或者你需要更大的东西,你就需要使用一些bignum库。

See this question for bignum libraries: Big numbers library in c++

请参见bignum库的这个问题:c++中的大数库。

#2


1  

I implemented a BigInteger for C++. You are welcome to use it.

我为c++实现了一个BigInteger。欢迎您使用它。

http://memmove.blogspot.com/2013/04/unlimited-unsigned-integer-in-c.html

http://memmove.blogspot.com/2013/04/unlimited-unsigned-integer-in-c.html

#1


1  

int or long types are not big enough for the values you're talking about.

int或long类型对于您所讨论的值来说不够大。

34! = 295232799039604140847618609643520000000

34 != 295232799039604140847618609643520000000

This barely fits into 128 bits. If your compiler supports a 128-bit number type, you can use it to calculate factorials up to 34. If not, or if you need anything larger, you will need to use some kind of bignum library.

这几乎不适合128位。如果您的编译器支持一个128位的数字类型,您可以使用它来计算多达34的阶乘。如果没有,或者你需要更大的东西,你就需要使用一些bignum库。

See this question for bignum libraries: Big numbers library in c++

请参见bignum库的这个问题:c++中的大数库。

#2


1  

I implemented a BigInteger for C++. You are welcome to use it.

我为c++实现了一个BigInteger。欢迎您使用它。

http://memmove.blogspot.com/2013/04/unlimited-unsigned-integer-in-c.html

http://memmove.blogspot.com/2013/04/unlimited-unsigned-integer-in-c.html