当前位置:网站首页>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;
}
运行结果

边栏推荐
- C语言 成绩排名
- 存储引擎分析
- Varnish 基础概览10
- MySQL function
- postman 之接口关联
- What is digital garbage? Follow the world's first AI artist to explore meta carbon Art
- Mysql 监控
- HC32M0+ GPIO
- Questions about database: database attachment
- Some thoughts on small program subcontracting and verification of uiniapp subcontracting optimization logic
猜你喜欢

MES管理系统功能模块之质量管理

C语言 害死人不偿命的(3n+1)猜想

I learned database at station B (V): DQL exercise

C语言 成绩排名

Stimulsoft Reports报告工具,Stimulsoft创建和构建报告
![【图神经网络】图分类学习研究综述[3]:图分类方法评价及未来研究方向](/img/b1/2afa73a14b2f41b7a65c4c2d261e6a.png)
【图神经网络】图分类学习研究综述[3]:图分类方法评价及未来研究方向

2020-12-03

C语言 换个格式输出整数

Seata 與三大平臺攜手編程之夏,百萬獎金等你來拿
![[recommendation system] concise principle and code implementation of user based collaborative filtering](/img/3b/d46e37e7ae245cf2931d32d1ebbe4c.png)
[recommendation system] concise principle and code implementation of user based collaborative filtering
随机推荐
Resizekit2.net size and resolution independent
浅析现代Web端im即时通讯开发技术
Varnish 基础概览6
How to build your own blog website by yourself
js逆向请求参数加密:
Quality management of functional modules of MES management system
I learned database at station B (V): DQL exercise
Mechanical --nx2007 (UG) -- gap analysis (interference inspection)
Newton method (optimization of two variable functions)
The 8th "Internet +" competition - cloud native track invites you to challenge
JS anti shake and throttling
Seata et les trois plateformes travaillent main dans la main pour programmer Summer, un million de bonus vous attend
Ansible ad-hoc 临时命令
Interview summary
App test related tools
Embedded exit (review and release)
Varnish 基础概览2
Rubymine development tool, refactoring and intention operation
MySQL function
How to deal with occasional bugs?