当前位置:网站首页>C language number prime
C language number prime
2022-06-30 01:31:00 【Martin の Blog】

Algorithm design ideas
- Be careful : The processing of prime numbers requires the use of sqrt Method , Otherwise, the operation will timeout
Code
#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;
}
Running results

边栏推荐
- MySQL monitoring 5
- 【图神经网络】图分类学习研究综述[3]:图分类方法评价及未来研究方向
- [mrctf2020]ezpop-1 | PHP serialization
- js返回内容被unicode编码
- MySQL monitoring 2
- Varnish foundation overview 3
- STC89C52 single chip microcomputer simple calculator design and code demonstration
- [535. encryption and decryption of tinyurl]
- cookie加密8
- Seata and the three platforms are working together in the summer of programming. Millions of bonuses are waiting for you
猜你喜欢

What should be paid attention to in the design and production of the Urban Planning Museum

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

Sentinel source code analysis Part 7 - sentinel adapter module - Summary

Preliminary understanding of NVIDIA Jetson nano

Embedded exit (review and release)

Chiffrement des cookies 8

Cookie encryption 11

ES6 one line code for array de duplication

Kubernetes core object overview details

TP-LINK configure WiFi authentication method for wireless Internet SMS
随机推荐
魔百盒CM201-2-CH-Hi3798MV300-300H-EMMC和NAND_红外蓝牙语音_通刷固件包
Spark 离线开发框架设计与实现
画画水族馆的应用特色及功能
【图神经网络】图分类学习研究综述[2]:基于图神经网络的图分类
c语言选择,循环概述
Mysql 监控3
Embedded exit (review and release)
js Array.from()的5个便捷应用
JS returned content is encoded by Unicode
Cookie encryption 12
R language linear regression model fitting diagnosis outliers analysis of domestic gas consumption and calorie examples with self-test questions
C language final without failing (Part 1)
Mysql 监控5
The 8th "Internet +" competition - cloud native track invites you to challenge
Embedded test template
Pytorch中transforms的用法整理
Sentinel source code analysis Part 7 - sentinel adapter module - Summary
c语言期末不挂科(上)
App test related tools
Design and implementation of spark offline development framework