我是靠谱客的博主 魁梧彩虹,这篇文章主要介绍[Loops]D. Liang 4.20 Printing Prime numbers between 2 and n.c[Loops]D. Liang 4.20 Printing Prime numbers between 2 and nDescriptionInputOutputNOTE:Sample InputSample Output,现在分享给大家,希望可以做个参考。

[Loops]D. Liang 4.20 Printing Prime numbers between 2 and n

Description

Write a program that reads an interger n, then print all the prime numbers between 2 and n, inclusively.

Input

An integer n (2<=n<=2000).

Output

All the prime number between 2 and n, inclusively.
You should display eight prime numbers per line, specify the width of each number’s print field to 5, justify the output to right.

NOTE:

  1. There is NO SPACE at the end of each line.
  2. There is A NEWLINE (n) at the end of last line iff it has eight number.

That is (. indicates <space> and ¬ indicates &lt;newline>)

复制代码
1
2
....2

or

复制代码
1
2
....2....3....5....7...11...13...17...19¬

Sample Input

复制代码
1
2
59

Sample Output

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Date:2020/3/19 // Author:xiezhg5 #include <stdio.h> #include <math.h> int main(void) { int count=0; int i,j,k; int m,n; m=2; scanf("%d",&n); for(i=m;i<=n;i++) { k=sqrt(i); //遍历2到√i的数即可 for(j=2;j<=k;j++) if(i%j==0) { break; //不是素数立即退出循环 } if(j>=k+1) { if(i==1) count=count; else { printf("%5d",i); count++; if(count%8==0) //注意输出要求 printf("n"); } } } printf("n"); return 0; }

最后

以上就是魁梧彩虹最近收集整理的关于[Loops]D. Liang 4.20 Printing Prime numbers between 2 and n.c[Loops]D. Liang 4.20 Printing Prime numbers between 2 and nDescriptionInputOutputNOTE:Sample InputSample Output的全部内容,更多相关[Loops]D.内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部