当前位置:网站首页>PTA:自测-2 素数对猜想 (20分)
PTA:自测-2 素数对猜想 (20分)
2022-06-12 14:51:00 【苏木George】
基本思路:先求出所有的素数对,然后在遍历一遍查看有多少对。
#include"stdio.h"
#include"math.h"
#include <cstdlib>
#include <iostream>
#include <queue>
using namespace std;
int sushu(int n)
{
int i=2;
if(n<2) return 0;
for(;i<=sqrt(n);i++){
if(n%i==0){
return 0;
}
}
return 1;
}
int main(){
queue<int> q;
int n =0;
scanf("%d",&n);
int m =0;
int s = 2;
for (int i=3;i<=n;i++){
if(sushu(i) == 1){
if((i-s) == 2){
m++;
}
s =i;
}
}
printf("%d",m);
}
边栏推荐
- 阿里、腾讯、拼多多垂范,产业互联网的新逻辑渐显
- ShardingSphere实践(6)——弹性伸缩
- 机器人前行、旋转的service编写
- Tu oses le croire? Il m'a fallu deux jours pour développer un système de gestion.
- [writeup]buu SQL course1[entry level]
- C scanf函数
- Prompt that the program cannot access key files / directories when installing PS software. Error code: 41
- Can you believe it? It took me only two days to develop a management system
- 我愿称之为史上最全的深度学习面经总结(附答案详解)
- 程序构造和解释之过程抽象
猜你喜欢
指针相关概念
SQL cross database injection
基于TensorRT的深度学习模型部署实战教程!
Ali suggests that all POJO attributes use wrapper classes, but have you noticed these pits?
Selenium advanced
Function recursion example
亿纬锂能拟募资90亿:刘金成骆锦红夫妇合计认购60亿 布局光谷
Jetpack architecture component learning (3) -- activity results API usage
C 字符串
Detailed explanation of factory pattern (simple factory pattern, factory method pattern, abstract factory pattern) Scala code demonstration
随机推荐
[wechat applet] 3 The first wechat applet
三维重建系统 | L3增量运动恢复结构(增量SFM)
Appnium (I) basic use of appnium
Junit多线程的写法
Jenkins' RPC test project
webdriver入门
[lambda operation jcf]
Autofac Beginner (1)
C data type
ADSL
Chapter I exercises of program construction and interpretation
数据的收集
C常量,不能改变
野指针理解
模块八
NETCORE combined with cap event bus to realize distributed transaction -- Introduction (1)
[gatewaysessioninactiveevent event] 1 Connect your own client disconnect
MySQL index and view
浏览器指纹解读
Swap numbers, XOR, operator correlation