Description:

Sexy primes are pairs of primes of the form (p, p+6), so-named since "sex" is the Latin word for "six". (Quoted from http://mathworld.wolfram.com/SexyPrimes.html)

Now given an integer, you are supposed to tell if it is a sexy prime.

Input Specification:

Each input file contains one test case. Each case gives a positive integer N (≤).

Output Specification:

For each case, print in a line Yes if N is a sexy prime, then print in the next line the other sexy prime paired with N (if the answer is not unique, output the smaller number). Or if N is not a sexy prime, print No instead, then print in the next line the smallest sexy prime which is larger than N.

Sample Input 1:

47

Sample Output 1:

Yes
41

Sample Input 2:

21

Sample Output 2:

No
23

Keys:

  • 素数

Attention:

  • 这几次很爱考素数,奶一口欧拉算法,9月份考试能不能中

Code:

 /*
SP数,P和P+6都是素数
给定一个正整数,判断N是否为SP数,打印与他配对的另一个素数(如果不唯一,输出较小的一个
如果N不是SP数,打印大于N的最小SP数 1,判断i-6是否大于n
2,n-6可能小于0,
*/
#include<cstdio> bool IsPrime(long long n)
{
if(n <= )
return false;
for(long long i=; i*i<=n; i++)
if(n%i == )
return false;
return true;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDEG int n;
scanf("%d",&n);
if(IsPrime(n-) && IsPrime(n))
printf("Yes\n%d", n-);
else if(IsPrime(n) && IsPrime(n+))
printf("Yes\n%d", n+);
else
{
for(int i=n+; i<1e9; i++)
if(IsPrime(i-) && IsPrime(i))
{
printf("No\n%d", i->n?i-:i);
break;
}
} return ;
}

PAT 2019-3 7-1 Sexy Primes的更多相关文章

  1. PAT 2019 春

    算是第二次做这套题吧,感觉从上次考试到现在自己有了挺大提高,提前30min做完了. 7-1 Sexy Primes 读懂题意就行. #include <cstdio> #include & ...

  2. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...

  3. PAT 2019 秋

    考试的还行.不过略微有点遗憾,但是没想到第一题会直接上排序和dfs,感觉这次的题目难度好像是倒着的一样.哈哈哈哈. 第一题实在是搞崩心态,这道题给我的感觉是,可以做,但事实上总是差点啥. 第二题,第三 ...

  4. PAT甲题题解-1015. Reversible Primes (20)-素数

    先判断n是否为素数然后把n转化成d进制下再反转,转化为十进制的num判断num是否为素数 注意n为0和1时,不是素数!!!注意反转后的num也有可能为1,不是素数!!! #include <io ...

  5. 【PAT Advanced Level】1015. Reversible Primes (20)

    转换进制&&逆序可以在一起进行,有一点技巧,不要用十进制数来表示低进制,容易溢出. #include <iostream> #include <vector> ...

  6. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  7. PAT甲级【2019年3月考题】——A1156 SexyPrimes【20】

    Sexy primes are pairs of primes of the form (p, p+6), so-named since “sex” is the Latin word for “si ...

  8. PAT(甲级)2019年春季考试

    7-1 Sexy Primes 判断素数 一个点没过17/20分 错因:输出i-6写成了输出i,当时写的很乱,可以参考其他人的写法 #include<bits/stdc++.h> usin ...

  9. 三月pat(转)

    转自https://blog.csdn.net/weixin_40688413/article/details/88082779 担心别人删除了就找不到了.因为九月要考. 7-1 Sexy Prime ...

随机推荐

  1. Python入门习题8.羊车门问题

    例8. 羊车门问题描述:有3扇关闭的门,一扇后停着汽车,另外两扇门后是山羊,主持人知道每扇门后是什么.参赛者首先选择一扇门.在开启它之前,主持人会从另外两扇门中打开一扇门,露出门后的山羊.此时,允许参 ...

  2. luoguP3391[模板]文艺平衡树(Splay) 题解

    链接一下题目:luoguP3391[模板]文艺平衡树(Splay) 平衡树解析 这里的Splay维护的显然不再是权值排序 现在按照的是序列中的编号排序(不过在这道题目里面就是权值诶...) 那么,继续 ...

  3. P4195 【模板】exBSGS/Spoj3105 Mod

    传送门 首先要懂得 $BSGS$,$BSGS$ 可以求出关于 $Y$ 的方程 $X^Y \equiv Z (mod\ mo)$ 的最小解,其中 $gcd(X,Z)=1$ $exBSGS$ 算是 $BS ...

  4. 在win7下面清除samba用户的登录状态

    相信会有一部分刚开始测试samba服务器的人会有过这样的疑惑? 在win7下面使用一个samba用户的username和passwd登录过后,之后每次进去都是以这样的username和passwd进去 ...

  5. Windows程序设计(七)--鼠标

    7.2 客户区鼠标消息 当鼠标移过窗口的显示区域时,窗口消息处理程序收到WM_MOUSEMOVE消息.当在窗口的显示区域中按下或者释放一个鼠标按键时,窗口消息处理程序会接收到下面这些消息: 键 按下 ...

  6. jsp常用代码

    1.头部 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&q ...

  7. XMPP即时通讯协议使用(五)——搭建简单的Openfire插件

    前言 在开发Openfire插件前需要构建完成服务器源码编辑环境,具体操作步骤请参照Openfire服务器源码编译的了解. 开发简单的Openfire插件 1.已构建完成的Openfire源码结构如下 ...

  8. JavaScript中正则使用

    字符串是编程时涉及到的最多的一种数据结构,对字符串进行操作的需求几乎无处不在.比如判断一个字符串是否是合法的Email地址,虽然可以编程提取@前后的子串,再分别判断是否是单词和域名,但这样做不但麻烦, ...

  9. mysql03--误删除了所有用户解决办法

    误删除了所有用户解决办法 第一种方法(企业常用) 1.将数据库down掉 [root@db03 mysql]# /etc/init.d/mysqld stop Shutting down MySQL. ...

  10. "sorted()"中的"Key Functions"

    Pythonsorted()函数中可以加入key=<FUNCTION>参数.作用是每个元素在排序之前,先作为key=<FUNCTION>中FUNCTION的参数,用FUNCTI ...