Check a Integer is power of 3 or not

Posted chuanwen-tech

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Check a Integer is power of 3 or not相关的知识,希望对你有一定的参考价值。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 /*错误代码
 5 bool solve(long long n)
 6 
 7     if(n%3==0)
 8         return true;
 9     else
10         return false;
11 */
12 
13 //题目给出32bit整数,可以依此来确定3在32bit下的最高次幂值,然后做模运算
14 bool solve(long long n)
15 
16     if(1162261467%n==0)
17         return true;
18     return false;
19 
20 
21 int main()
22 
23     int t;
24     cin>>t;
25     while(t--)
26     
27         long long n;
28         cin>>n;
29         if(solve(n))
30             cout<<"Yes"<<endl;
31         else
32             cout<<"No"<<endl;
33     
34     return 0;
35 

 

以上是关于Check a Integer is power of 3 or not的主要内容,如果未能解决你的问题,请参考以下文章

lintcode-easy-O Check Power of 2

HDOJ3208 Integer’s Power

Check if a configuration profile is installed on iOS

A server is already running. Check tmp/pids/server.pid.

Check whether a remote server port is open on Linux

Check if a string is NULL or EMPTY using PowerShell