how to convert n into an integer m that can be represented in the form 2^x+2^y (where x and y are non-negative integers such that x???y)
Answers
Answered by
0
In this you will get an idea on how to implement the abover format:
bool isPower(unsigned n)
{
if (n==1) return true;
// Try all numbers from 2 to sqrt(n) as base
for (int x=2; x<=sqrt(n); x++)
{
unsigned y = 2;
unsigned p = pow(x, y);
// Keep increasing y while power 'p' is smaller
// than n.
while (p<=n && p>0)
{
if (p==n)
return true;
y++;
p = pow(x, y);
}
}
return false;
}
Similar questions