QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#36199#1863. Yes, Prime MinisterFroggyguaWA 100ms29724kbC++17778b2022-06-25 19:54:412022-06-25 19:54:43

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-25 19:54:43]
  • 评测
  • 测评结果:WA
  • 用时:100ms
  • 内存:29724kb
  • [2022-06-25 19:54:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define N 20002000
typedef long long ll;
int T;
bool ntp[N];
int p[N>>2],pn;
void init(int n){
	ntp[1]=1;
	for(int i=2;i<=n;++i){
		if(!ntp[i])p[++pn]=i;
		for(int j=1;j<=pn&&p[j]*i<=n;++j){
			ntp[p[j]*i]=1;
			if(i%p[j]==0)break;
		}
	}
}
int x;
void Solve(){
	cin>>x;
	if(x<=0){
		x=-x;
		if(!ntp[x]){
			cout<<2*x+2<<'\n';
		}
		else if(!ntp[x+x+1]){
			cout<<2*x+2<<'\n';
		}
		else{
			cout<<-1<<'\n';
		}
	}
	else{
		if(!ntp[x]){
			cout<<1<<'\n';
		}
		else if(!ntp[2*x-1]||!ntp[2*x+1]){
			cout<<2<<'\n';
		}
		else{
			cout<<-1<<'\n';
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	init(20000001);
	cin>>T;
	while(T--){
		Solve();
	}
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 100ms
memory: 29724kb

input:

10
-2
-1
0
1
2
3
4
5
6
7

output:

6
4
2
2
1
1
2
1
2
1

result:

wrong answer 3rd numbers differ - expected: '3', found: '2'