我试图在 C++ 变量中放置一个大数字。号码是600851475143
我尝试使用 unsigned long long int,但收到一个错误,提示常量太大。 然后我尝试了一个名为 BigInt 的 bigInt 库 -> http://mattmccutchen.net/bigint/
问题是我无法编译代码,因为我收到很多关于库的错误。
对 `BigInteger::BigInteger(int)' 的 undefined reference <-- 很多。
到目前为止,这是我的代码:
#include "string"
#include "iostream"
#include "bigint/NumberlikeArray.hh"
#include "bigint/BigUnsigned.hh"
#include "bigint/BigInteger.hh"
#include "bigint/BigIntegerAlgorithms.hh"
#include "bigint/BigUnsignedInABase.hh"
#include "bigint/BigIntegerUtils.hh"
using namespace std;
int main() {
//unsigned long int num = 13195;
//unsigned long long int num = 600851475143;
BigInteger num = 13195;
int divider = 2;
//num = 600851475143;
while (1) {
if ((num % divider) == 0) {
cout << divider << '\n';
num /= divider;
}
else
divider++;
if (num == 1)
break;
}
}
如果我输入较小的数字并且不使用 BigInt 库,则该程序运行良好。 任何帮助将不胜感激:D
最佳答案
你可以通过后缀L来指定一个整型字面值。
您可以通过后缀 LL 指定一个 long long 的整数文字。
#include <iostream>
int main()
{
long long num = 600851475143LL;
std::cout << num;
}
关于c++ - C++ 中的大数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/238343/