PAT (Basic Level) Practise (中文)1013数素数 (20)
来源:互联网 发布:ibatis mysql 分页 编辑:程序博客网 时间:2024/05/29 12:03
原题如下
1013. 数素数 (20)
时间限制
100 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
令Pi表示第i个素数。现任给两个正整数M <= N <= 104,请输出PM到PN的所有素数。
输入格式:
输入在一行中给出M和N,其间以空格分隔。
输出格式:
输出从PM到PN的所有素数,每10个数字占1行,其间以空格分隔,但行末不得有多余空格。
输入样例:5 27输出样例:
11 13 17 19 23 29 31 37 41 4347 53 59 61 67 71 73 79 83 8997 101 103
提交代码
笔者用C++写出代码如下
#include "iostream"#include "math.h"using namespace std;int main(){ int m,n,gs=0,i=2,j,dycs=0; cin>>m>>n; while(1) { for(j=2; j<sqrt(i); j++) { if(i%j==0) { break; } } if(j>sqrt(i)&&i!=4) { gs++; } if(j>sqrt(i)&&gs>=m&&gs<n&&i!=4) { dycs++; if(dycs%10==0) cout<<i<<endl; else cout<<i<<" "; } else if(j>sqrt(i)&&gs==n) { cout<<i; dycs++; if(dycs%10==0) cout<<endl; } if(gs>n) break; i++; } return 0;}
C++提交结果如下
0 0
- PAT (Basic Level) Practise (中文)1013数素数 (20)
- PAT (Basic Level) Practise (中文)1013. 数素数 (20)
- PAT (Basic Level) Practise (中文) 1013. 数素数 (20)
- PAT (Basic Level) Practise (中文)1013. 数素数 (20)
- PAT (Basic Level) Practise (中文)1013. 数素数 (20)
- PAT (Basic Level) Practise (中文)1013. 数素数 (20) C语言
- PAT (Basic Level) Practise (中文) 1064. 朋友数(20)
- PAT (Basic Level) Practise (中文)1064. 朋友数(20)
- PAT (Basic Level) Practise (中文)1002.写出这个数
- PAT (Basic Level) Practise (中文)1007. 素数对猜想 (20)
- PAT (Basic Level) Practise (中文)1007. 素数对猜想 (20) C语言
- PAT (Basic Level) Practise (中文)1007素数对猜想 (20)
- PAT (Basic Level) Practise (中文) 1007. 素数对猜想 (20)
- PAT (Basic Level) Practise (中文)1007. 素数对猜想 (20)
- PAT(basic level) 1013 数素数(20)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)--1001
- 深入理解ajax系列第三篇——响应解码
- CodeForces 104C【树特性】
- 滴滴出行进制转换
- 【SSH网上商城项目实战11】查询和删除商品功能的实现
- 斐波那契数列
- PAT (Basic Level) Practise (中文)1013数素数 (20)
- 创建型模式总结
- 数组去重
- Linux下的网络配置命令
- CentOS下建立硬链接和软链接
- CCF数位之和JAVA答案
- \r,\n,\r\n的区别
- 设计模式(三) 单例模式
- 前端开发-移动端(1)