C++ long long int 的限制是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34842637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the limit of long long int ?
提问by Yash Kant
I find numeric limits of long long int insufficient. Is there any other numeric type in C++ like big integer in java?
我发现 long long int 的数字限制不够。C++ 中是否还有其他数字类型,如 Java 中的大整数?
I stumbled upon this question recently and didn't knew how to tackle it..... https://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/
我最近偶然发现了这个问题,不知道如何解决它..... https://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/
回答by encoreleeet
unsigned long long int is biggest integer type in standard C++ ( it can hold numbers from 0 to 18 446 744 073 709 551 615 ), if you want bigger ones you may need to search for some bignum libraries like this: http://www.ttmath.org/
unsigned long long int 是标准 C++ 中最大的整数类型(它可以保存从 0 到 18 446 744 073 709 551 615 的数字),如果你想要更大的数字,你可能需要搜索一些像这样的 bignum 库: http://www .ttmath.org/
回答by rbashish
回答by Subash Chandra Manohari
You can use the C++ library <boost/multiprecision/cpp_int.hpp>
for such problems.
您可以使用 C++ 库<boost/multiprecision/cpp_int.hpp>
解决此类问题。
For example:
例如:
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
namespace mp = boost::multiprecision;
using namespace std;
int main()
{
mp::cpp_int f = 1;
for(int i = 1; i <= 100; i++)
f *= i;
cout << "100! = " << f << '\n';
}
This will give the output
这将给出输出
100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
To know more about C++ boost library, you can refer hereand here