求民间数据/求调/求hack
查看原帖
求民间数据/求调/求hack
482660
konyakest楼主2023/3/19 11:31

你谷民间数据自测95pts,但是ccf官方数据A了

求民间数据/求调/求hack

code:

#include<bits/stdc++.h>
using namespace std;
#define F(i,j,k) for(signed i=signed(j);i<=signed(k);i++)
#define endl '\n'

#define DEBUG

#ifdef DEBUG
template<typename T>void dbg(const T& x){cerr<<x<<endl;}
template<typename T,typename... Args>void dbg(const T& x,const Args& ...r){cerr<<x<<" ";dbg(r...);}
#define debug(...) {cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" = ";dbg(__VA_ARGS__);}
#else
#define debug(...)
#endif

using ll=unsigned long long;

ll n,k;
vector<ll> v;

ll qPow(ll a,ll b){
	ll ans=1;
	while(b){
		if(b%2) ans=ans*a;
		a=a*a;
		b/=2;
	}
	return ans;
}

ll my_sqrt(ll a,ll b){
	long double ans=powl(a,1.0/b);
	for(int i=ans+3;;i--){
		double aa=powl(i,b);
		if(aa>2*a) continue;
		if(qPow(i,b)<=a) return i;
	}
}

signed main(){
	freopen("power.in","r",stdin);
	freopen("power.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	if(k==1) cout<<n<<endl,exit(0);
	if(k==2){
		F(i,3,__lg(n)){
			ll limit=my_sqrt(n,i);
			F(j,1,limit) v.push_back(qPow(j,i));
		}
		sort(begin(v),end(v));
		int siz=unique(begin(v),end(v))-begin(v);
		// for(auto i:v) debug(i);

		vector<ll> tmp;
		F(i,0,siz-1) tmp.push_back(v[i]);
		v.clear();
		for(auto i:tmp){
			ll p=my_sqrt(i,2);
			if(p*p!=i) v.push_back(i);
		}

		// for(auto i:v) debug(i);
		// debug((ll)sqrtl(n));
		cout<<(ll)my_sqrt(n,2)+(ll)v.size()<<endl;
	}
	else{
		// debug(__lg(n));
		F(i,k,__lg(n)){
			ll limit=my_sqrt(n,i);
			// debug(i,limit);
			F(j,1,limit) v.push_back(qPow(j,i));
		}
		// for(auto i:v) debug(i);
		sort(begin(v),end(v));
		cout<<unique(begin(v),end(v))-begin(v)<<endl;
	}
	return 0;
}
2023/3/19 11:31
加载中...