I saw this question, and pop up this idea.
Here's a general algorithm for finding out if a number is a power of another number:
bool IsPowerOf(int n,int b) { if (n > 1) { while (n % b == 0) { n /= b; } } return n == 1; }