当前位置:网站首页>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);
}
边栏推荐
猜你喜欢

三维重建系统 | L3双视角运动恢复结构(SFM双目SFM)
![[wp][入门]攻防世界-game](/img/07/1ea54d14ba3caca25a68786d5be4a6.png)
[wp][入门]攻防世界-game

能链智电登陆纳斯达克:贝恩是股东 成中国充电服务第一股

Dataset and dataframe in sparksql
![[Writeup]BUU SQL COURSE1[入门级]](/img/eb/1b2541b04ca231cb07f1f3706f51c7.png)
[Writeup]BUU SQL COURSE1[入门级]

Mobileone: the mobile terminal only needs 1ms of high-performance backbone. You deserve it!

tc菜单分割

Function recursion example

Autofac Beginner (1)

Jetpack architecture component learning (3) -- activity results API usage
随机推荐
Autofac Beginner (1)
粒子滤波学习记录
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Structure example
你敢信?開發一個管理系統我只用了兩天
Getting started with webdriver
[wp][入门]攻防世界-game
[lambda operation jcf]
Swap numbers, XOR, operator correlation
JS (I) error [err\u module\u not\u found]: cannot find package 'UUID' imported
[spark][core] interview questions talk about push based shuffle
Open Chinese path file in C language
ADB control installation simulator
Writing method of JUnit multithreading
ROS中tf学习笔记
Chapter I exercises of program construction and interpretation
【SimpleDateFormat】1. Conversion of date type and text type 2 Thread unsafe
selenium之元素定位
Interview (XI) futu written test questions
C string