5TLE求助
查看原帖
5TLE求助
693931
caitou007楼主2022/3/25 20:49

O(n*loh(n))的复杂度不行的吗?

#include<bits/stdc++.h>
using namespace std;
long long n,q;
long long sum=0,ans=0;
long long a[12345678]={0},b[12345678]={0};
bool cmp(long long x){
	if(x==2){
		return 1;
	}
	if(x==3){
		return 1;
	}
	for(long long i=2;i*i<=x;i++){
		if(x%i==0){
			return 0;
		}
	}
	return 1;
}
int main(){
	long long j=1;
	std::ios::sync_with_stdio(0);
	cin>>n>>q;
	for(long long i=1;i<=q;i++){
		cin>>a[i];
	}
	for(long long i=2;i<=sqrt(n);i++){
	     if(cmp(i)){
	     	b[j++]=i;
		 }
	}
	for(long long i=1;i<=q;i++){
	   cout<<b[a[i]];
	}
	return 0;
}
2022/3/25 20:49
加载中...