题意:判断一个数是不是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. 千人基因组计划数据库下载某段区域SNP

    进入http://browser.1000genomes.org/index.html网站 假定要寻找“6:133098746-133108745”这段距离的SNP数据,“6”表示6号染色体,后面的数 ...

  2. POJ 3352-Road Construction (图论-双边联通分支算法)

    题目大意:一个图,要求你加入最少的边,使得最后得到的图为一个边双连通分支.所谓的边双连通分支,即不存在桥的连通分支(题目保证数据中任意两点都联通). 解题思路:先用tarjan算法进行缩点建立DAG图 ...

  3. HTTP协议-引自孤傲苍狼博客

    一.什么是HTTP协议 HTTP是hypertext transfer protocol(超文本传输协议)的简写,它是TCP/IP协议的一个应用层协议,用于定义WEB浏览器与WEB服务器之间交换数据的 ...

  4. JavaWeb---图书馆管理系统

    写在开头,以后每天写记录. 今天,初步了解了一下,项目需求,用现在自己所学的知识,很多还不能做出来. 先用目前的知识,一步步的做出来,不断的完善,今天遇到的问题: 任务分析: 01.list页面的ad ...

  5. FZU 1894 志愿者选拔 (单调队列)

    /****************************************************************** 题目: 志愿者选拔(FZU 1894) 算法: 单调队列 算法思 ...

  6. vs代码段快捷键设置

    1 工具->代码段管理器

  7. firemonkey中stringgrid属性大全

    StringGrid之属性大全: Align:                            //确定组件在父类组件区内的对齐方式(alScale:随窗口 放大缩小) AlterRowBack ...

  8. ADB工具常用指令和使用情形分析

    一.ADB常用命令:(不需要进到设备,也就是:不需要执行adb shell) adb devices 列出所有的已连接的设备 adb kill-server 关闭adb adb start-serve ...

  9. MYSQL 查询出最大/最小值所在的记录

    基本上都知道用MAX()/MIN()来求出所需的最大/最小值,但是只能查出那个最值的字段,而想查出整条记录或是对应的其他值却不行(SELECT MAX(grade), name FROM test;- ...

  10. jquery_easyui 相关问题

    1. datagrid点击title,无法进行客户端排序. 增加属性 data-options="singleSelect:true,collapsible:true,url:'/ViewS ...