当前位置:网站首页>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);
}
边栏推荐
- SQL cross database injection
- 【Optional】1. Map and ifpresent 2 Ofnullable and orelse
- 程序构造和解释之过程抽象
- jenkins的RPC测试项目
- C常量,不能改变
- Prompt that the program cannot access key files / directories when installing PS software. Error code: 41
- JD scanning code to obtain cookies
- Writing method of JUnit multithreading
- win10_ Home Edition cannot use remote desktop, and can be accessed by remote desktop.
- odom坐标系的理解
猜你喜欢

指针相关概念

Ankai microelectronics rushes to the scientific innovation board: the annual revenue of 500million Xiaomi industry fund is the shareholder

用游戏来讲序列化与反序列化机制

JS (II) syntaxerror: cannot use import statement outside a module

C main函数

结构体示例

JMeter (V) pressure test of Excel file upload interface

Assertion of selenium webdriver

Writing method of JUnit multithreading
![[wechat applet] 6.1 applet configuration file](/img/8c/eadaa6d0cadde459c3f817a23303ea.jpg)
[wechat applet] 6.1 applet configuration file
随机推荐
USART(RS232422485)、I2C、SPI、CAN、USB总线
产业端:618的新战场
Prompt that the program cannot access key files / directories when installing PS software. Error code: 41
Unit test (I) unit test with JUnit
阿裏、騰訊、拼多多垂範,產業互聯網的新邏輯漸顯
Chapter I exercises of program construction and interpretation
Writing method of JUnit multithreading
交换数字,异或求单,操作符相关
[SPARK][CORE] 面试问题之什么是 external shuffle service?
C语言打开中文路径文件
[spark][core] what is an external shuffle service?
Leader education was forced to be delisted: Softbank CMC suffered heavy losses only one year after listing
JS (III) convert ES6 syntax to Es5 syntax
selenium之元素定位
NETCORE combined with cap event bus to realize distributed transaction - message (2)
浏览器指纹解读
三维重建系统 | L3双视角运动恢复结构(SFM双目SFM)
安装PS软件时提示程序无法访问关键文件/目录,错误代码:41的解决方法
[wechat applet] 1 Introduction to wechat applet
Open Chinese path file in C language