杭电2012素数判定
来源:互联网 发布:建模数据挖掘师 编辑:程序博客网 时间:2024/05/05 22:15
输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。
Output
对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。
Sample Input
0 10 0
Sample Output
OK
#include<iostream>#include<cmath>using namespace std;int isprime(int x){ int i; double m=sqrt(x*1.0); for(i=2;i<=m;i++) if(x%i==0) break; if(i>m&&i!=1&&i!=0)return 1; else return 0;}int main(){ int i,n,y,z,flag; int x; while(cin>>x>>y) { flag=0; if(x==0&&y==0)break; for(i=x;i<=y;i++) { z=i*i+i+41; if(!isprime(z)) { flag=1;break; } } if(flag==1) cout<<"Sorry"<<endl; else cout<<"OK"<<endl; } return 0;}
0 0
- 杭电 2012 素数判定
- 杭电2012素数判定
- 2012杭电 素数判定
- 杭电 2012 素数判定
- 【杭电】[2012]素数判定
- 【杭电2012】素数判定
- 【杭电】2012 素数判定
- 杭电2012素数判定
- 【杭电】素数判定
- 杭电ACM 2012 素数判定
- 杭电ACM 2012 素数判定
- 杭电ACM 2012素数判定----20140723
- 素数判定(杭电2012)
- 杭电ACM 2012:素数判定
- 杭电 acm 2012(素数判定)
- 【杭电-oj】-2012-素数判定
- 杭电oj 2012 素数判定
- 文章标题 杭电 2012 素数判定
- 安卓SDK API下载
- Ubuntu下,清屏等终端常用命令
- hehe
- SDUT_2015寒假集训_动规递推_A-蟠桃记
- [最短路径] HDU 1869 - 六度分离
- 杭电2012素数判定
- 电脑中为何有些文件无法删除
- 推荐!国外程序员整理的系统管理员资源大全
- 程序员之路——如何学习C语言并精通C语言
- How to program the QBoard1, 2 and 3
- java内存分析
- shell替换功能
- 作为
- Python之迭代器(iterator)