当前位置:网站首页>性感素数(Acwing每日一题)
性感素数(Acwing每日一题)
2022-07-27 05:21:00 【最后一只三脚兽】

题目较简单,就是判断一个数num是否是性感素数只要三步
- num是否是素数
- num+6是否是素数,是就返回num-6
- num-6是否是素数,是就返回num+6
先开始判断一下,如果不是性感素数就用while循环让num不断+1,直到找到性感素数为止。
#include<bits/stdc++.h>
using namespace std;
int N;
bool judge(int num) {
if (num < 2) return false;
for (int i = 2; i <= sqrt(num); i++) {
if (num % i == 0)return false;
}
return true;
}
//获取匹配的性感素数,没有就返回-1
int getSex(int num) {
if (!judge(num))return -1;
if (judge(num - 6))return num - 6;
if (judge(num + 6))return num + 6;
return -1;
}
int main()
{
cin >> N;
if (getSex(N) != -1) {
cout << "Yes" << endl;
cout << getSex(N) << endl;
return 0;
}
cout << "No" << endl;
while (N++) {
if (judge(N)) {
if (getSex(N) != -1) {
cout << N << endl;
return 0;
}
}
}
return 0;
}
边栏推荐
- 【头歌】重生之我在py入门实训中(5):列表
- Day 3. Suicidal ideation and behavior in institutions of higher learning: A latent class analysis
- Auto Encoder(AE),Denoising Auto Encoder(DAE), Variational Auto Encoder(VAE) 区别
- 【头歌】重生之我在py入门实训中(9):异常处理
- 物联网操作系统多任务基础
- 能替代ps的修图软件?
- [first song] rebirth of me in py introductory training (4): Circular program
- [first song] rebirth of me in py introductory training (1)
- 关于druid连接不上数据库的问题
- One of the usage of operator()
猜你喜欢

浅记一下十大排序

Super remote connection management tool: Royal TSX

Cesium教程 (1) 界面介绍-3dtiles加载-更改鼠标操作设置

超强远程连接管理工具:Royal TSX

STM32-红外遥控

Stm32-fsmc extended memory SRAM

物联网操作系统
![[Haowen planting grass] knowledge of root domain name - Ruan Yifeng's Weblog](/img/75/8f41db9f9c077b43751d63b7b5b57e.png)
[Haowen planting grass] knowledge of root domain name - Ruan Yifeng's Weblog

Multi task foundation of IOT operating system

安全帽反光衣检测识别数据集和yolov5模型
随机推荐
When multiple formulas in latex share a sequence number
【5·20特辑】MatLAb之我在和你表白
C language - linear sequence table
LaTeX中多个公式公用一个序号时
编程学习记录——第8课【数组与设计五子棋,扫雷游戏】
[first song] rebirth of me in py introductory training (1)
【头歌】重生之深度学习篇-Keras(初级)
malloc和new之间的不同-实战篇
【头歌】重生之我在py入门实训中(1)
[song] rebirth of me in py introductory training (8): module
Multi task foundation of IOT operating system
力扣题解 二叉树(8)
STM32 infrared remote control
力扣题解 二叉树(6)
编程学习记录——第7课【函数】
Weidongshan digital photo frame project learning (I) display ASCII characters on LCD
[high concurrency] interviewer
C# Json编码在TCP通讯中的一些使用总结
超强远程连接管理工具:Royal TSX
物联网操作系统多任务基础