pat:1013 质数
来源:互联网 发布:阿里云收件服务器 编辑:程序博客网 时间:2024/05/02 01:47
http://pat.zju.edu.cn/contests/pat-b-practise/1013
1.判断素数
2.输出格式控制
#include <stdio.h>#include <math.h>bool isPrime(int x){int y = (int)sqrt(x);for(; x%y != 0; y--){}return y == 1;}int main(){#ifdef ONLINE_JUDGE#elsefreopen("E:\\in.txt", "r", stdin);//freopen("E:\\out.txt", "w", stdout);#endifint m,n;while(scanf("%d %d", &m , &n) != EOF){int num=1;int cn=0, index=0;int dist= n-m+1;while(++num){if(isPrime(num)){cn++;if(cn >= m && cn <= n){index++;if(index%10 == 0 || index == dist)printf("%d\n", num);elseprintf("%d ", num);}if (cn == n)break;//end}//prime}//while}//whilereturn 0;}
0 0
- pat:1013 质数
- PAT (Advanced Level) 1015. Reversible Primes (20) 翻转质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- spring 的singleton 和prototype的区别和应用场合
- Git入门指南六:移除文件和移动文件
- C++ 定义string类型变量
- 三星在MWC大会上发布两款新的Gear智能手表
- __I、 __O 、__IO是什么意思?怎么用?
- pat:1013 质数
- 用大津法进行omr识别
- rman实现不完全恢复
- uva 1291 - Dance Dance Revolution(dp)
- Partition List - LeetCode
- 【linux学习笔记】top命令总结
- Spring中IoC的入门实例
- 12306网站设计猜想
- mysql时区转换查询,convert_tz