分析
法1:求出第一个小于等于这个数的 2 n 2^n 2n的数。因为质因数最多的肯定是 2 n 2^n 2n,所以只需要考虑把其中一个2换成一个大一点的数,使得乘积等于输入的x。而这个数不能大于2*2(这样就会大于2n+1),所以只能换成3。暴力判断即可。
法2:思想跟法1一样,直接分解质因数2,看看剩下的是否<=3。
上代码
法一
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll t,n;
ll a[64],tot;
void pre()
{
ll s=1;
while(s<=1e18)
{
s*=2;
a[++tot]=s;
}
}
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1) ans*=x;
x*=x;
y>>=1;
}
return ans;
}
int main()
{
pre();
cin>>t;
while(t--)
{
scanf("%lld",&n);
ll l=lower_bound(a+1,a+tot+1,n)-a;
if(ksm(2,l)>n) l--;
if(ksm(2,l-1)*3==n||ksm(2,l)==n) cout<<0<<endl;
else cout<<1<<endl;
}
return 0;
}
法二
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll t,n;
int main()
{
cin>>t;
while(t--)
{
scanf("%lld",&n);
while(n%2==0) n/=2;
if(n<=3) cout<<0<<endl;
else cout<<1<<endl;
}
return 0;
}