Problem : Given a positive integer which fits in a 32 bit signed integer, find if it can be expressed as A^B where B > 1 and A > 0. A and B both should be integers.
Below is the C implementation of above problem
#include<stdio.h> int isPower(int A) { int i,a; double p; if(A == 1) return 1; for(a = 1;a <= sqrt(A);a++) { p = log(A) / log(a); if(p - (int)p < 0.000000001) return 1; } return 0; } int main() { printf("%d",isPower(16)) }
Output
1
If you found any bugs or have suggestion plz comment below .. HAPPY CODING !! 🙂