I tried to solve the problem 1475A - Нечетный делитель, Where the problem is rather simple we have to check if a number is a power of 2 if true then print NO and if false then YES.It was solved but I thought if I could find if a number x is power of y for long long numbers.So, I wrote the following function:
bool isPowerofN(long long num, long long base)
{
double log_num = (log(num) / log(base));
int x = floor(log_num);
int y = ceil(log_num);
if (x == y)
return true;
else
return false;
}
The result are correct in my device(mac m1-gcc (Homebrew GCC 11.2.0_3) 11.2.0)
But when submit the code it gives error for larger numbers like 10^40=1099511627776. Here is the submission : 169948113 It should output NO but give YES instead.
So, is there a problem with the implementation or is there another way to check this in constant time ?




