当前位置:网站首页>Sexy prime number (summer vacation daily question 1)
Sexy prime number (summer vacation daily question 1)
2022-07-26 14:55:00 【sweetheart7-7】
“ Sexy prime ” It is shaped like ( p , p + 6 ) (p,p+6) (p,p+6) Such a pair of prime numbers .
It's called , Because the Latin tube “ 6、 ... and ” It's called “ s e x sex sex”( That is, English “ sexy ”).
Now give an integer , Please judge whether it is a sexy prime .
Input format
Input gives a positive integer on a line N N N.
Output format
if N N N It's a sexy prime , Output in one line Yes, And output and on the second line N N N Another sexy prime paired ( If such a number is not unique , The one with the smaller output ).
if N N N Not a sexy prime , Output in one line No, Then output greater than... On the second line N N N The minimum number of sexy prime .
Data range
1 ≤ N ≤ 1 0 8 1≤N≤10^8 1≤N≤108
sample input 1:
47
sample output 1:
Yes
41
sample input 2:
21
sample output 2:
No
23
#include<iostream>
using namespace std;
bool is_prime(int n){
if(n < 2) return false;
for(int i = 2; i <= n / i; i++)
if(n % i == 0) return false;
return true;
}
int is_sex_prime(int x){
if(is_prime(x) && is_prime(x - 6)) return -1;
if(is_prime(x) && is_prime(x + 6)) return 1;
return 0;
}
int main(){
int n;
cin >> n;
int flag = is_sex_prime(n);
if(!flag) {
puts("No");
while(!is_sex_prime(n)) n++;
cout << n << endl;
}else{
puts("Yes");
if(flag == -1) cout << n - 6 << endl;
else cout << n + 6 << endl;
}
return 0;
}
边栏推荐
- Arithmetic operation and logic operation of image in opencv
- SiamRPN++:深层网络连体视觉跟踪的演变
- Simple implementation of pytorch
- 什么是传输层协议TCP/UDP???
- WPF common function integration
- CAS单点登录
- Parsing XML files using Dom4j
- Next generation visual transformer: Unlocking the correct combination of CNN and transformer
- 31. Opinion based relational pivoting forcross domain aspect term extraction reading notes
- [untitled]
猜你喜欢

TransC知识表示模型

BSN IPFs (interstellar file system) private network introduction, functions, architecture and characteristics, access instructions

SiamRPN:建议区域网络与孪生网络

Simple implementation of pytorch

Seata deployment and microservice integration

数据权限就该这么设计,yyyds!

RPN:Region Proposal Networks (区域候选网络)
网络图片转本地导致内核退出
Network pictures are transferred locally, causing the kernel to exit

jmeter分布式
随机推荐
SA Siam: Twin network for real-time target tracking
Pdf translation, which translation company in Beijing is good
[1.2. return and risk of investment]
What is the problem of the time series database that has been developed for 5 years?
CAS single sign on
14. Bridge based active domain adaptation for aspect term extraction reading notes
OSPF和MGRE实验
How to evaluate the test quality?
Use of delve for go development and debugging
Tdengine helps Siemens' lightweight digital solution simicas simplify data processing process
SiamRPN++:深层网络连体视觉跟踪的演变
Kubernetes----Pod配置资源配额
[integer programming]
sqlDeveloper工具快速入门
Parsing XML files using Dom4j
【整数规划】
Kubernetes ---- pod configuration resource quota
【华为联机对战服务】客户端退出重连或中途进入游戏,新玩家如何补帧?
WPF common function integration
解决Typora图片显示不出来问题