Short solution in C++ for this topic


#1

int Solution::isPower(int A) {
int solution = 0;
if (A == 1) {
return 1;
}
for (int i = 2; i < A; i++) {
if (A % i == 0) {
int t = A;
int count = 0;
while (t % i == 0) {
t = t / i;
count++;
}
if (t == 1) {
return 1;
}
}
}
return 0;
}