2021中国大学生程序设计竞赛(CCPC)- 网络选拔赛(重赛)1004

Primality Test

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 5305    Accepted Submission(s): 2464


 

Problem Description
A positive integer is called a prime if it is greater than 1 and cannot be written as the product of two smaller positive integers. A primality test is an algorithm for determining whether an input number is a prime. For example, the Miller-Rabin primality test is a probabilistic primality test. This problem is precisely the one about the primality test.

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.

 
g(x)=⌊f(x)+f(f(x))2⌋
 

Input
The first line of the input contains an integer T (1≤T≤105), indicating the number of test cases.

Each test case contains an integer x (1≤x≤1018) in a single line.
 

Output
For each test case, if g(x) is a prime, output 𝚈𝙴𝚂 in a single line. Otherwise, output 𝙽𝙾 in a single line.
 

Sample Input
 
 
2 1 2
 

Sample Output
 
 
YES NO
 

Hint

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭晋龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值