QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#62343#1863. Yes, Prime MinisterlmeowdnWA 354ms325972kbC++171.3kb2022-11-18 12:08:132022-11-18 12:08:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-18 12:08:14]
  • 评测
  • 测评结果:WA
  • 用时:354ms
  • 内存:325972kb
  • [2022-11-18 12:08:13]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define eb emplace_back
#define fi first
#define se second
#define pc __builtin_popcount
typedef pair<int,int> pii;
typedef vector<int> vi;

long long read() {
	long long res=0, w=1; char c=getchar();
	while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
	while(isdigit(c)) {res=res*10+c-'0'; c=getchar();}
	return res*w;
}

const int N=2e7+9;
int pr[N],tot,vst[N],nxt[N];
int T,x[N];

void pre(int n=2e7) {
	vst[1]=1;
	rep(i,2,n) {
		if(!vst[i]) pr[++tot]=i;
		for(int j=1;j<=tot&&pr[j]*i<=n;j++) {
			vst[i*pr[j]]=1;
			if(i%pr[j]==0) break;
		}
	}
	per(i,n,0) {
		if(!vst[i]) nxt[i]=i;
		else nxt[i]=nxt[i+1];
	}
}

signed main() {
	T=read();
	pre();
	rep(i,1,T) {
		int x=read();
		if(x==0) {
			puts("3");
		} else if(x>0&&!vst[x]) {
			puts("1");
		} else if(x>0&&(!vst[2*x+1]||!vst[2*x-1])) {
			puts("2");
		} else {
			int l=x, r=2-x, ans=1e9;
			if(l>r) swap(l,r);
			if(!vst[r-l+1]) ans=min(ans,r-l+1);
			l=x, r=1-x;
			if(l>r) swap(l,r);
			int len=r-l+1;
			if(len%2==0) len/=2;
			if(!vst[len]) ans=min(ans,r-l+1);
			if(ans==1e9) ans=-1;
			printf("%lld\n",ans);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 337ms
memory: 325900kb

input:

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

output:

6
4
3
2
1
1
2
1
2
1

result:

ok 10 numbers

Test #2:

score: -100
Wrong Answer
time: 354ms
memory: 325972kb

input:

201
-100
-99
-98
-97
-96
-95
-94
-93
-92
-91
-90
-89
-88
-87
-86
-85
-84
-83
-82
-81
-80
-79
-78
-77
-76
-75
-74
-73
-72
-71
-70
-69
-68
-67
-66
-65
-64
-63
-62
-61
-60
-59
-58
-57
-56
-55
-54
-53
-52
-51
-50
-49
-48
-47
-46
-45
-44
-43
-42
-41
-40
-39
-38
-37
-36
-35
-34
-33
-32
-31
-30
-29
-28
-27...

output:

202
-1
199
197
194
193
191
-1
-1
-1
-1
181
178
-1
-1
173
-1
-1
166
-1
163
-1
158
157
-1
-1
151
149
146
-1
142
-1
139
137
134
-1
131
-1
127
-1
122
-1
118
-1
-1
113
-1
109
106
-1
103
101
-1
97
94
-1
-1
89
86
-1
82
-1
79
-1
74
73
71
-1
67
-1
62
61
58
-1
-1
53
-1
-1
46
-1
43
41
38
37
34
-1
31
29
26
-1
2...

result:

wrong answer 2nd numbers differ - expected: '202', found: '-1'