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

边栏推荐
- ctfshow 大赛原题 680-695
- Seata 與三大平臺攜手編程之夏,百萬獎金等你來拿
- Stimulus reports reporting tool, stimulus creates and builds reports
- Some thoughts on small program subcontracting and verification of uiniapp subcontracting optimization logic
- 传统微服务框架如何无缝过渡到服务网格 ASM
- JS recursive summation 1-100
- 英伟达Jetson Nano的初步了解
- cookie加密8
- js Array.from()的5个便捷应用
- Is the course of digging money reliable and safe to open an account?
猜你喜欢

Cub school learning: manual query and ADC in-depth use

TP-LINK configure WiFi authentication method for wireless Internet SMS

Some thoughts on small program subcontracting and verification of uiniapp subcontracting optimization logic

Tetris game based on STM32F103

C语言 我要通过

【推荐系统】基于用户的协同过滤简明原理与代码实现

我,33岁,字节跳动测试开发,揭开北京“测试岗”的真实收入

英伟达Jetson Nano的初步了解

Mechanical --nx2007 (UG) -- gap analysis (interference inspection)
![[recommended] how to quickly locate a bug during testing](/img/7a/726b2ea02ac5feb40e7378ba49e060.jpg)
[recommended] how to quickly locate a bug during testing
随机推荐
Analysis of IM instant messaging development technology on modern web
ctfshow 大赛原题 680-695
C语言 我要通过
Quality management of functional modules of MES management system
post请求出现WebKitFormBoundaryk的解决办法
C语言 继续(3n+1)猜想
【机器学习Q&A】余弦相似度、余弦距离、欧式距离以及机器学习中距离的含义
C language final without failing (Part 1)
js Array.from()的5个便捷应用
Sentinel source code analysis Part 7 - sentinel adapter module - Summary
Varnish 基础概览2
Interview summary
Varnish 基础概览1
对深度网络模型量化工作的总结
Mechanical --nx2007 (UG) -- gap analysis (interference inspection)
Vl6180x distance and light sensor hands-on experience
How to deal with occasional bugs?
[mrctf2020]ezpop-1 | PHP serialization
[machine learning Q & A] accuracy, accuracy, recall, ROC and AUC
“乘风破浪”的芒果超媒,能上岸吗?