当前位置:网站首页>C语言 素数对猜想
C语言 素数对猜想
2022-06-30 01:25:00 【Martin の Blog】

算法设计思路
- 获取素数(注意,该部分课程产生运行超时,使用sqrt可以解决)
- 判断素数是否相邻
- 打印结果
代码
#include <stdio.h>
#include <math.h>
int issushu(int x){
int count = 0;
for(int i=2; i<sqrt(x)+1; i++){
if(x % i==0){
return 0;
}
}
return 1;
}
int main(){
int n, i;
int x=0;
scanf("%d", &n);
for(i=5; i<=n; i++){
if(issushu(i-2) && issushu(i)){
x++;
}
}
printf("%d", x);
return 0;
}
运行结果
边栏推荐
猜你喜欢

Online sql to CSV tool

画画水族馆的应用特色及功能

How to view the size of all files in a folder?
![[535. encryption and decryption of tinyurl]](/img/b7/7748febe30852ca428fe86b045e9ca.png)
[535. encryption and decryption of tinyurl]

Wechat applet - requestsubscribemessage:fail can only be invoked by user tap gesture

How to seamlessly transition from traditional microservice framework to service grid ASM

Is the numpy index the same as the image index?
![【图神经网络】图分类学习研究综述[2]:基于图神经网络的图分类](/img/5f/b23b64eed7f28ffd92c122b6859e2d.png)
【图神经网络】图分类学习研究综述[2]:基于图神经网络的图分类

【机器学习Q&A】余弦相似度、余弦距离、欧式距离以及机器学习中距离的含义

Cookie加密10
随机推荐
In depth analysis of a large number of clos on the server_ The root of wait
Ctfshow competition original title 680-695
VIM编辑器常用指令
Statsmodels notes STL
How to view the size of all files in a folder?
C language selection, loop overview
Shell spec date format
眼底出血术后需注意事项//每天必看
如何统一项目中包管理器的使用?
js返回内容被unicode编码
Online text digit recognition list summation tool
How latex enters a matrix
Varnish 基础概览7
The 8th "Internet +" competition - cloud native track invites you to challenge
Mysql 监控6
c语言选择,循环概述
Cantilever beam calculation [matlab code]
Cloud, IPv6 and all-optical network
Machinery -- nx2007 (UG) finite element analysis tutorial 2 -- assembly
Is the numpy index the same as the image index?