80pts求调 WA
查看原帖
80pts求调 WA
359354
Beihai_Jiang楼主2024/11/12 23:59

WA#16 #18 #19 #20
分类讨论k=1,k=2,k3k=1,k=2,k\geq3

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k,ans,c;
map<ll,bool> m;//查重 
int main(){
	cin>>n>>k;
	if(k==1){
		cout<<n;
		return 0;
	}
	m[1]=1;
	ans=1;
	if(k==2){
		for(ll i=2;i<=n;i++){//枚举底数 
			if(i*i*i>n) break;
			ll p=3;
			while(pow(i,p)<=n){
				ll temp=pow(i,p);
				if(!m[temp]){//判断是否出现过 
					m[temp]=1;
					ans++; 
					if((ll)sqrtl(temp)*(ll)sqrtl(temp)==temp)
						c++;//重复个数 
				}
				p++;
			}
		}
		cout<<ans+(ll)sqrtl(n)-1-c;//k=3的答案+a^2的答案-重复的答案 
		return 0;
	}
	for(ll i=2;i<=n;i++){
		if(pow(i,k)>n) break;
		ll p=k;//指数最少为k 
		while(pow(i,p)<=n){
			ll temp=pow(i,p);
			if(!m[temp]){
				ans++;
				m[temp]=1;
			}
			p++;//指数++ 
		}
	}
	cout<<ans;
	return 0;
}
2024/11/12 23:59
加载中...