版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sxy201658506207/article/details/84677282
g(n)是n的因子和
A a b 查询a b区间有多少个n满足上式。
Q a 查询a满不满足式子
参考
#include <bits/stdc++.h>
//#include <iostream>
//#include <cstdio>
#define X 10005
#define inF 0x3f3f3f3f
#define PI 3.141592653589793238462643383
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
const int Times=10;
const ll inf= 9223372036854775807;
int N=1e6+10;
ll primer[maxn],a[maxn];
//int ans[maxn],num[maxn];
ll Pow(ll a,ll n)
{
ll ans=1;
while(n)
{
if(n&1)
{
ans=ans*a;
}
a=a*a;
n>>=1;
}
return ans;
}
bool Prime(ll n)
{
for(int i=2;i<=sqrt(n);++i)
{
if(n%i==0)
return false;
}
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int cnt=0;
for(int i=2;i<60;++i) // i=1会得出 1 可 1 不是完全数
{
ll ans=Pow(2,i)-1;
if(Prime(ans))
a[cnt++]=ans*Pow(2,i-1); // (充要条件)欧几里得完全数公式:如果2p−1是素数,则2p−1⋅(2p−1)是完全数
}
// ll a[8]={6,28,496,8128,33550336,8589869056,137438691328LL,2305843008139952128LL};
ll x,y,n;
char s;
while(cin>>s)
{
if(s=='A')
{
cin>>x>>y;
int sum=0;
if(x>y)
x=x^y^(y=x);
for(int i=0;i<cnt;++i)
{
if(x<=a[i]&&a[i]<=y)
sum++;
}
cout<<sum<<endl;
}
else
{
cin>>n;
int i=0;
for(i=0;i<cnt;++i)
{
if(a[i]==n)
{
cout<<1<<endl;
break;
}
}
if(i==8)
cout<<0<<endl;
}
}
return 0;
}