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?
记录一下函数 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
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
相关文章推荐
- boost解析json文件
- PHP开源框架 CodeIgniter
- Angularjs学习笔记6_table1
- 十大推送方式整理
- 浅谈Web网站架构演变过程
- 无马时代
- Git基本使用命令
- 【译】通过Hardware Layer提升Android动画性能
- GCJ 2009 Round 1C Bribe the Prisoners
- 判断两点间是否有整数点共线
- 软件需求分析
- ORA-01034: ORACLE not available Shared memory realm does not exist
- poj1006.。
- git常用操作
- PDOStatement 类 FETCH_* 系列
- 递归和尾递归的比较,斐波那契
- js基本知识
- Excel的列编号 例如:A对应1,Z对应26,AA对应27,AZ对应52 ......
- 汇编语言中常用的伪指令
- 对象池