我想在C++變量中放置一個大數字。數字是600851475143C++中的大數字
我試過unsigned long long int但得到一個錯誤,說它常量太大。 我然後嘗試bigInt庫稱爲BigInt - >http://mattmccutchen.net/bigint/
問題是我無法編譯的代碼,因爲我得到許多關於lib的錯誤。
未定義對`BigInteger :: BigInteger(int)'的引用'< - 很多這些。
這是到目前爲止我的代碼:
#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;
}
}
如果我把一個小數目和lib這個程序運行正常不使用BigInt有。 任何幫助將不勝感激:d
歐拉項目#3 ...這是一個棘手的問題...我有同樣的問題。我也看了一下BigInt lib,但我注意到他們沒有正確實現postfix操作符......所以我認爲潛伏在他們的代碼中會存在其他問題。 – paxos1977 2008-10-27 16:27:09