95分求助!!
查看原帖
95分求助!!
1120828
linjinkun楼主2024/3/11 21:11

用了暴力+小技巧

#include<bits/stdc++.h>
using namespace std;
#define int long long
map<int,int>b;
signed main()
{
	int ans = 0;
	int num = 0;
	int n,k;
	scanf("%lld %lld",&n,&k);
	if(k == 1)
	{
		printf("%lld",n);
		return 0;
	}
	for(int i = 2;i<=cbrt(n);i++)
	{
		for(int j = k;j<=log(n)/log(i);j++)
		{
			int q = pow(i,j);
			if(b.find(q)!=b.end())
			{
				continue;
			}
			if(sqrt(q)-floor(sqrt(q)) == 0)
			{
				num++;
			}
			b[q] = 1;
			ans++;
		}
	}
	if(k == 2)
	{
		ans+=floor(sqrt(n))-num-1;
	}
	printf("%lld",ans+1);
    return 0;
}
2024/3/11 21:11
加载中...