题意:判断一个数是不是4的幂数,和Power of two类似。

先判断num是否大于0,再判断num是否能开根号,最后判断num开根号后的数是否是2^15的约数。

提示:4的幂数开根号就是2的幂数。

注意:判断一个双精度数a是否是0,请用fabs(a)<一个极小的数,如本题中用的是1e-9。

 class Solution {
public:
bool isPowerOfFour(int num) {
return (num > ) && (fabs((int)sqrt(num) -sqrt(num)) <1e- ) && ((<<) % ((int)sqrt(num)) == );
}
};

Leetcode 342 Power of Four 数论的更多相关文章

  1. [LeetCode] 342. Power of Four 4的次方数

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...

  2. LeetCode 342. Power of Four (4的次方)

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...

  3. LeetCode 342. Power of Four

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...

  4. Leetcode 231 Power of Two 数论

    同样是判断数是否是2的n次幂,同 Power of three class Solution { public: bool isPowerOfTwo(int n) { ) && ((( ...

  5. Python [Leetcode 342]Power of Four

    题目描述: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Examp ...

  6. [LeetCode] 342. Power of Four(位操作)

    传送门 Description Given an integer (signed 32 bits), write a function to check whether it is a power o ...

  7. Leetcode 326 Power of Three 数论

    判断一个数是否是3的n次幂 这里我用了一点巧,所有的int范围的3的n次幂是int范围最大的3的n次幂数(即3^((int)log3(MAXINT)) =  1162261467)的约数 这种方法是我 ...

  8. [LeetCode] 231 Power of Two && 326 Power of Three && 342 Power of Four

    这三道题目都是一个意思,就是判断一个数是否为2/3/4的幂,这几道题里面有通用的方法,也有各自的方法,我会分别讨论讨论. 原题地址:231 Power of Two:https://leetcode. ...

  9. 231. Power of Two 342. Power of Four -- 判断是否为2、4的整数次幂

    231. Power of Two Given an integer, write a function to determine if it is a power of two. class Sol ...

随机推荐

  1. android里R.layout.的问题

    今天,在Exlipse里的一个项目在.java文件里写  setContentView(R.layout.activity_problem);时,显示错误,以为是R.java文件里没有对应的activ ...

  2. FreeBSD_11-系统管理——{Part_3-网络}

    一.Network Servers DNS unbound/local_unbound # /etc/rc.conf local_unbound_enable="YES" # 测试 ...

  3. 【Map】获取字符串中,每一个字母出现的次数

    package cn.itcast.p1.map.test; import java.util.Iterator; import java.util.Map; import java.util.Tre ...

  4. C#基础(1)

    .NET的开发方向,有三种: ① 桌面开发系统,即WinForm: ② Internet应用程序,ASP.NET,其实也就是网站开发: ③ 手机开发,WP7,Windows Phone 7. .NET ...

  5. yield学习续:yield return迭代块在Unity3D中的应用——协程

    必读好文推荐: Unity协程(Coroutine)原理深入剖析 Unity协程(Coroutine)原理深入剖析再续 上面的文章说得太透彻,所以这里就记一下自己的学习笔记了. 首先要说明的是,协程并 ...

  6. Map:containsKey、containsValue 获取Map集合的键值的 值

    get(Object key) 返回与指定键关联的值: containsKey(Object key) 如果Map包含指定键的隐射,则返回true: containsValue(Object valu ...

  7. 第38讲:List伴生对象操作方法代码实战

    今天来看一下List伴生对像的操作方法 让我们来看下代码  println(List.apply(1,2,3))//等同于List(1,2,3)     println(List.range(1, 4 ...

  8. 原生js运动框架

    function getStyle(obj,name){ if(obj.currentStyle) { return obj.currentStyle[name]; } else { return g ...

  9. windows小技巧 从文件夹直接打开命令行位置

    windows下从命令行打开某个目录下的东东时,会一直cd  ~~~~,更简单的是: 直接用鼠标找到该文件夹或者文件,按住Shift键然后点击鼠标右键,选择"在此处打开命令行"即可 ...

  10. 使用jsPlumb制作流程图设计器

    jsPlumb是一个比较强大的绘图组件,它提供了一种方法,主要用于连接网页上的元素.在现代浏览器中,它使用SVG或者Canvas技术,而对于IE8以下(含IE8)的古董浏览器,则使用VML技术. 项目 ...