fork download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. bool isPowerOfThree(int n) {
  5. if(n<=0) return 0;
  6. while(n%3==0)
  7. n/=3;
  8. if(n==1) return 1;
  9. else return 0;
  10. }
  11. int main(){
  12. int n;
  13. scanf("%d",&n);
  14. bool result=isPowerOfThree(n);
  15. (result==0)? printf("false"):printf("true");
  16. return 0;
  17. }
Success #stdin #stdout 0.01s 5292KB
stdin
6
stdout
false