I'm trying to solve 56th problem of Project Euler and I have some troubles while using the Big Integer Library. Here is the code :
#include <iostream>
#include "BigInteger.hh"
#include <cmath>
using namespace std;
int digitSum(BigInteger x){
int num[(int)floor(log10(x))+2];
int n = 0;
BigInteger sum = 0;
while (x != 0){
sum += x - floor(x/10) * 10;
x = floor(x/10);
n++;
}
return sum.toInt();
}
int main(int argc, const char * argv[])
{
int max = 0;
for (int i = 1; i <= 100; i++){
for (int j = 1; j <= 100; j++){
cout << "i = %i, j = %i ",i,j;
if (digitSum(pow(i,j)) < max)
max = digitSum(pow(i,j));
}
}
cout << digitSum(pow(2,63));
return 0;
}
The problem is that when I try building, the compiler gives error on the lines using the log10
, floor
, and pow
functions saying that they are used but not defined. When I comment the line #include "BigInteger.hh"
, everything goes fine but this time, of course, I can't use the Big Integer library.
Why is there such a problem? How to solve it?