leecode 解题总结:342. Power of Four
来源:互联网 发布:淘宝溢价是什么意思 编辑:程序博客网 时间:2024/06/05 00:10
#include <iostream>#include <stdio.h>#include <vector>#include <string>using namespace std;/*问题:Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example:Given num = 16, return true. Given num = 5, return false.Follow up: Could you solve it without loops/recursion?分析:一个数如果能被4整除,则该数Num必定存在log4(Num)的值为0注意都取10为底,取e为底,存在精度问题输入:165输出:truefalse关键:1 一个数如果能被4整除,则该数Num必定存在log4(Num)的值为0注意都取10为底,取e为底,存在精度问题*/class Solution {public: bool isPowerOfFour(int num) { double result = log10(num) / log10(4);return (result - (int)result) == 0 ? true : false; }};void process(){ int num; Solution solution; while(cin >> num ) { bool result = solution.isPowerOfFour(num); if(result) { cout << "true" << endl; } else { cout << "false" << endl; } }}int main(int argc , char* argv[]){process();getchar();return 0;}
0 0
- leecode 解题总结:342. Power of Four
- leecode 解题总结:326. Power of Three
- [leetcode] 342. Power of Four 解题报告
- leetcode 342. Power of Four 解题报告
- leetcode解题报告-342. Power of Four
- [Leetcode] 342. Power of Four 解题报告
- 342. Power of Four
- 342. Power of Four
- 342. Power of Four
- 342. Power of Four
- 342. Power of Four
- 342. Power of Four
- 342. Power of Four
- 342. Power of Four
- 342. Power of Four
- 342. Power of Four
- 342. Power of Four
- 342. Power of Four
- 树的存储结构
- hdu1242 Rescue BFS+优先队列
- 选票统计
- Java的安全初始化
- python 调用 有道api接口
- leecode 解题总结:342. Power of Four
- 为什么(i++)不能做左值,而(++i)可以
- ACM-最难的问题(字符串处理)
- 【L3_002】堆栈【线段树】
- php函数microtime
- JasperReport6.3.1官网下载
- 记第一次面试
- 国内随时接收发送谷歌邮箱
- 通过Filter设置HTTP hander中的cache-control