题意:判断一个数是不是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. 前端---HTML

    HTML基础 本章内容: 简介 HTML定义 标签定义和属性 HTML5基本结构 HTML5字符集 <head>标签 <title> <base/> <lin ...

  2. plupload简易应用 多图片上传显示预览以及删除

    <script> var uploader = new plupload.Uploader({ //实例化一个plupload上传对象 browse_button: 'btnBrowse' ...

  3. 一个有趣的基于C++的模拟发牌程序

    在内存中模拟出一副牌,然后模拟洗牌,发牌等动作. 流程是这样的:构建一副牌保存到一个数组中—洗牌—创建玩家—向玩家发牌–输出每个玩家的牌. #include <stdio.h> #incl ...

  4. 应该了解的Python模块

    Python很优雅.使用以下模块有助于保持你的代码整洁.易于维护.欢迎补充. Docopt.忘了optparse和argparse吧,使用docstring来构建优雅的.高可读性.复杂(如果你有这个需 ...

  5. [转载]tail No space left on device

    转载http://www.chenxie.org/?p=717 # tail -f ../logs/catalina.outtail: cannot watch `../logs/catalina.o ...

  6. PAT

    PAT将每个全局IP地址的可用端口号分为3个部分0~511,512~1023,1023~65535.当PAT从地址池中获取地址时,首先维持源端口不变.如果不可能,它再从池中起始部分搜索可用的端口,如果 ...

  7. 修改Broforce无限人数,死亡不减反加

    看B站直播发现这个有趣的游戏,找了半天修改器无效,Cheat Engine怎么找指针有点忘了,直接找数值每关都要重来,想来想去还是简单粗暴的反编译好了. 顺便做下C#反编译备忘. 首先把DLL反成IL ...

  8. 解决Win7下打不开chm文件的方法

    win7 无法打开chm操作如下:1,在命令行运行regsvr32 itss.dll2,在命令行运行regsvr32 hhctrl.ocx

  9. mono for android代码记录1 WebClient Post数据到Nopcommerce(post数据到MVC5)

    WebClient Post数据到Nopcommerce(post数据到MVC5) 注意事项 1.把[ValidateAntiForgeryToken]注释掉,以后再处理CSRF攻击.现在学习先不理 ...

  10. Linux 配置主机名

    方法 1:临时配置 [root@NING ~]# hostname NING CRT重新连接即可,服务器重启失效. 方法 2:永久配置 步骤1:包含了主机最基本的网络信息,用于系统启动. [root@ ...