I was wrong, you shouldn't use integer arithmetic for the lg(n) part
the idea is to obtain ceil(n lg n), but with you comparison
total <= maxOperations
that's already take care of
Also, run some tests and the precision of `double' seems good enough in the range that you need
so you may keep
double total
and use cmath functions
now, looking at your last code you have
1 2 3 4 5
|
total = num;
for (int numOfPowersToGo = 4; numOfPowersToGo > 0; --numOfPowersToGo) { //this executes 4 times
total *= num;
std::cout << total << '\n';
}
|
you are doing n^5 there
start with
total = 1
you make the same mistake with the 2^n part
1 2 3 4 5
|
total = 2;
// for each num in n, multiply original2Num by 2:
for(unsigned int i = 1; i <= num; ++i) {
total *= 2;
}
|
you are computing 2^(n+1)
which makes me wonder who gived you the testcases
1 2 3
|
// For Algo Type 2:
assert(solve(10, 3, 2) == "TLE"); //2^3 = 8, this should be "AC"
assert(solve(16, 3, 2) == "AC");
|
there is function exp2() for that.
> also, you should probably interrupt the n! and 2^n functions when then exceed 1e9
>> Putting this part on hold until we figure out the log & power issues. (Mainly a note to self).
you are doing a loop on the factorial, your code will take too much time to compute 1000000000!