326. Power of Three

Given an integer, write a function to determine if it is a power of three.

Follow up:
Could you do it without using any loop / recursion?

判断整数是不是3的幂数

 

1 bool isPowerOfThree(int n) {
2     // 1162261467 is 3^19,  3^20 is bigger than int  
3     return ( n>0 &&  1162261467%n==0);
4 }

 

posted @ 2016-05-20 20:44  米开朗菠萝  阅读(353)  评论(0)    收藏  举报