Big number in C++
biginteger, c++
Solution
You can specify an integer literal as long by the suffix L. You can specify an integer literal as long long by the suffix LL.
#include <iostream>
int main()
{
long long num = 600851475143LL;
std::cout << num;
}
Problem
I am trying to place a big number in a C++ variable. The number is 600851475143 I tried unsigned long long int but got an error saying it the constant was too big. I then tried a bigInt library called BigInt -> http://mattmccutchen.net/bigint/ The problem is I can't compile the code as I get many errors regarding the lib. undefined reference to `BigInteger::BigInteger(int)' <-- lot's of these. Here is my code so far: ``` #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; } } ``` If I put a smaller number and don't use the BigInt lib this program runs fine. Any help will be appreciated :D