Primality Test
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 5305 Accepted Submission(s): 2464
Let's define the function f(x) as the smallest prime which is strictly larger than x. For example, f(1)=2, f(2)=3, and f(3)=f(4)=5. And we use ⌊x⌋ to indicate the largest integer that does not exceed x.
Now given x, please determine whether g(x) is a prime.
Each test case contains an integer x (1≤x≤1018) in a single line.
When x=1, f(x)=2, f(f(x))=f(2)=3, then g(x)=⌊2+32⌋=2, which is a prime. So the output is 𝚈𝙴𝚂.
When x=2, f(x)=3, f(f(x))=f(3)=5, then g(x)=⌊3+52⌋=4, which is not a prime. So the output is 𝙽𝙾.
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int T;
cin >> T;
while (T --)
{
long long x;
scanf("%lld", &x);
if (x == 1){
puts("YES");
} else {
puts("NO");
}
}
return 0;
}
593



被折叠的 条评论
为什么被折叠?



