题意:给定 ,求多少 可被表示为 且 的个数。
首先发现 时,答案为 。
时,枚举 暴力处理,复杂度 。
大于 的部分只会贡献平方,对于 的处理可以先加上 ,在枚举时只选择不是平方数的加上,最后注意 精度不够,需使用 。
#include <bits/stdc++.h>
using namespace std;
map <long long,bool> f;
int main()
{
long long n;
int k;
scanf("%lld%d",&n,&k);
if(k==1)
{
printf("%lld\n",n);
return 0;
}
long long ans=1;
if(k==2)
ans=sqrtl(n);
for(int i=2;i<=1e6;i++)
{
long long x=i;
if(n/x<i)
continue;
for(int j=2;j<=60;j++)
{
x*=i;
if(k==2&&(long long)sqrtl(x)*sqrtl(x)!=x&&!f[x])
{
ans++;
f[x]=1;
}
if(k>2&&j>=k&&!f[x])
{
ans++;
f[x]=1;
}
if(n/x<i)
break;
}
}
printf("%lld\n",ans);
return 0;
}