当前位置:网站首页>C语言 数素数
C语言 数素数
2022-06-30 01:25:00 【Martin の Blog】
算法设计思路
- 注意点:素数的处理需要使用sqrt方法,不然运行会超时
代码
#include <stdio.h>
#include<math.h>
int check_su(int n){
int i;
int temp=sqrt(n);
for(i=2;i<=temp;i++){
if(n%i==0){
break;
}
}
if(i>temp){
return 0;
}else{
return 1;
}
}
int main(){
int n, m;
scanf("%d %d", &n, &m);
int count = 0;
int index = 0;
for(int i=1; i<1000000; i++){
if(check_su(i)==0){
if(count>=n && count<=m){
index++;
if(index % 10 == 0){
printf("%d\n", i);
}else{
if(index == (m-n)+1){
printf("%d", i);
break;
}else{
printf("%d ", i);
}
}
}
count++;
}
}
return 0;
}
运行结果
边栏推荐
- Seata and the three platforms are working together in the summer of programming. Millions of bonuses are waiting for you
- 81. 搜索旋转排序数组 II
- JS content confusion, return content encryption
- Mysql 监控5
- How to build your own blog website by yourself
- 快手伸手“供给侧”,找到直播电商的“源头活水”?
- Understanding of int argc, char * * argv in C language main function
- Sentinel source code analysis Chapter 9 - core process - lookprocesschain finding resource processing chain
- Statsmodels notes STL
- Cloud, IPv6 and all-optical network
猜你喜欢
Cub school learning: manual query and ADC in-depth use
ES6 one line code for array de duplication
MES管理系统功能模块之质量管理
【论文写作】英文论文写作指南
Stimulsoft Reports报告工具,Stimulsoft创建和构建报告
【图神经网络】图分类学习研究综述[3]:图分类方法评价及未来研究方向
TP-LINK configure WiFi authentication method for wireless Internet SMS
首届·技术播客月开播在即
C语言 继续(3n+1)猜想
Ansible ad-hoc 临时命令
随机推荐
C语言 换个格式输出整数
R language linear regression model fitting diagnosis outliers analysis of domestic gas consumption and calorie examples with self-test questions
81. 搜索旋转排序数组 II
我,33岁,字节跳动测试开发,揭开北京“测试岗”的真实收入
Varnish 基础概览1
ResizeKit2.NET大小和分辨率独立
Quality management of functional modules of MES management system
c语言选择,循环概述
【图神经网络】图分类学习研究综述[3]:图分类方法评价及未来研究方向
关于c语言main函数中int argc,char **argv的理解
Kubernetes 核心对象概览详解
Machine learning notes: time series decomposition STL
Cloud, IPv6 and all-optical network
2020-12-03
Varnish 基础概览8
js逆向请求参数加密:
cookie加密8
如何统一项目中包管理器的使用?
VIM editor common instructions
js内容混淆,返回内容加密