您的位置:首页 > 其它

leetcode 326. Power of Three

2016-04-09 18:14 447 查看
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?

class Solution {
public:
bool isPowerOfThree(int n) {
return (fmod(log10(n)/log10(3),1))==0;
}
};


记录一下函数 fmod 的用法如下:

原型:extern float fmod( float x, float y);

用法:#include < math.h >

功能:计算x/y的余数

说明:返回 x-n*y,符号同y。n=[x/y] (向靠近零的方向取整)

例如:fmod(3.6 , 1)= 0.6; fmod(-3.6 , 1)= -0.6;fmod(3.6 , -1)= -0.6
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: