# TopCoder12584 SemiPerfectPower

$$l \leq a*b^c \leq r(1 \le a < b)?$$的个数

1. $$c>3$$$$c$$是偶数.

1. $$c>3$$$$c$$是奇数.

$$a*x^2=b*y^3$$

$$a*x^2$$显然只需要枚举$$i \in [1,\sqrt[3]{x}]$$然后就是$$\sqrt{x/i}-i$$,因为要排除掉$$a \ge x$$的情况.

/*
mail: [email protected]
author: MLEAutoMaton
This Code is made by MLEAutoMaton
*/
#include<bits/stdc++.h>
using namespace std;
const int M=430890,N=16820;
class SemiPerfectPower{
public:
vector<int>son[M],sum[N];
int mu[M],thr_out[M];
int pfg(long long x){
int l=0,r=3e8,ret=0;
while(l<=r){
int mid=(l+r)>>1;
if(1ll*mid*mid<=x){ret=mid;l=mid+1;}
else r=mid-1;
}
return ret;
}
int lfg(long long x){
int l=0,r=M,ret=0;
while(l<=r){
int mid=(l+r)>>1;
if(1ll*mid*mid*mid<=x){ret=mid;l=mid+1;}
else r=mid-1;
}
return ret;
}
long long solve(long long x){
long long ans=0;
for(int i=1;1ll*i*i*i<=x;i++)if(mu[i])ans+=pfg(x/i)-i;
for(int i=1;1ll*i*i*i*i<=x;i++)
if(!thr_out[i])
for(int j=1;j*j*j<=i;j++){
int d=__gcd(j*j,i);
if(!mu[i/d])continue;
int k=j*j/d,l=i/k,r=lfg(x/i)/k;
for(int u:son[i/d])ans+=mu[u]*(sum[u][r/u]-sum[u][l/u]);
}
return ans;
}
long long count(long long l,long long r){
mu[1]=1;
for(int i=1;i<M;i++)if(mu[i])for(int j=i<<1;j<M;j+=i)mu[j]-=mu[i];
for(int i=1;i<M;i++)if(mu[i])for(int j=i;j<M;j+=i)if(mu[j])son[j].push_back(i);
for(int i=2;i*i*i<M;i++)for(int j=i*i*i;j<M;j+=i*i*i)thr_out[j]=1;
for(int i=1;i<N;i++){
sum[i].resize(M/i+1);
sum[i][0]=0;
for(int j=1;j<M/i+1;j++)
sum[i][j]=sum[i][j-1]+(mu[i*j]!=0);
}
return solve(r)-solve(l-1);
}
};

TopCoder12584 SemiPerfectPower

(0)
(0)