当前位置:网站首页>Pat class B 1013 C language
Pat class B 1013 C language
2022-06-23 05:54:00 【Octopus bro】
1013. Prime number (20)
Make Pi It means the first one i Prime number . Now give two positive integers M <= N <= 104, Please export PM To PN All prime numbers of .
Input format :
Enter... On one line M and N, Separated by spaces .
Output format :
Output from PM To PN All prime numbers of , Every time 10 Two figures account for 1 That's ok , Separated by spaces , But there must be no extra space at the end of the line .
sample input :5 27sample output :
11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103
Ideas : from 2 Start , Add one to the count variable every time a prime number is encountered , On this basis, judge whether it is greater than M, Is less than N.
One 、 Starting variable
1.M、N
2.count, Prime count variables
3.enterFlag Newline count variable , When this value is 10 Output line wrap on , And will enterFlag Assign a new value to 1
Two 、 operation
1. Input M N
2. Start from 2 Traverse , Every time we encounter a prime number , Count variables plus one , Until the count variable is N-1
3. Count variables plus one , Then judge whether it is greater than M
3. Then judge whether line feed is required , If there is no need to judge whether there is a blank space
3、 ... and 、 Code
// Starting time 21:42
#include "stdio.h"
#include "math.h"
int isPrime(int n);
int main()
{
int M,N;
M = N = 0;
scanf("%d %d", &M, &N);
int i;
int count = 0;
int enterFlag = 1;
// Start from 2 Traverse , Every time we encounter a prime number , Count variables plus one , Until the count variable is N-1
for(i = 2; count < N; i++)
{
if(isPrime(i))
{
count++;// Count variables plus one , Then judge whether it is greater than M
if(count >= M)
{
if(enterFlag != 10)// Then judge whether line feed is required , If there is no need to judge whether there is a blank space
{
if(count == N)
{
printf("%d",i);
enterFlag++;
}
else
{
printf("%d ",i);
enterFlag++;
}
}
else
{
printf("%d\n",i);
enterFlag = 1;
}
}
}
}
return 0;
}
int isPrime(int n)
{
int ret = 1;
int i = 2;
if(n == 2)
{
return ret;
}
int s = sqrt(n);
for(i = 2; i <= s; i++)
{
if(n % i == 0)
{
ret = 0;
break;
}
}
return ret;
}边栏推荐
- 制造业数字化转型存在问题及原因分析
- [image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code
- Real MySQL interview question (30) -- shell real estate order analysis
- 【斯坦福计网CS144项目】Lab2: TCPReceiver
- PAT 乙等 1022 D进制的A+B
- Analysis on the problems and causes of digital transformation of manufacturing industry
- Heimdall database proxy scale out 20 times
- MySQL面试真题(二十三)——拼多多-球赛分析
- [graduation season u; advanced technology Er] farewell to the confused self in the past two years. Regroup, junior I'm coming
- Leetcode topic analysis: factorial training zeroes
猜你喜欢

The performance of nonstandard sprintf code in different platforms

Wechat applet: elderly blessing short video

Redis cache penetration solution - bloom filter

MySQL面试真题(二十二)——表连接后的条件筛选及分组筛选

visdom的使用

jvm-03.jvm内存模型

技术开发团队视角看到的数字藏品机遇与挑战

云原生数据库是未来

C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)

ArcTime 制作中英文字幕视频
随机推荐
PAT 乙等 1014 C语言
数字化工厂建设可划分为三个方面
编址和编址单位
What is the magic of digital collections? Which reliable teams are currently developing
Heimdall database proxy scale out 20 times
The author believes that the so-called industrial Internet is a process of deep integration of industry and the Internet
线性表 链表结构的实现
Pit filling for abandoned openssl-1.0.2 (.A to.So)
啊哈C语言 第8章 游戏时间到了(第29讲)
MySQL面试真题(二十六)——滴滴2020年笔试题
Basic calculator II for leetcode topic analysis
啊哈C语言 第7章 有了它你能做更多的事(第27-28讲)
阿里云 ACK One、ACK 云原生 AI 套件新发布,解决算力时代下场景化需求
Yingjixin ip5566 with type-C port 3A charging and discharging fast charging mobile power supply 5W wireless charging in one SOC
JS面试题----防抖函数
云原生数据库是未来
Opencv display image
Basic calculator for leetcode topic analysis
PAT 乙等 1016 C语言
mysql字符集