hdu 2012 素数判定
来源:互联网 发布:p2p下载软件推荐 编辑:程序博客网 时间:2024/05/01 14:27
题目:
Problem Description
对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数。
Input
输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。
Output
对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。
Sample Input
0 10 0
Sample Output
OK
#include <cstdio>#include <cmath>#include <iostream>#include <cstring>#include <algorithm>#include <queue>#include <stack>#include <vector>#include <map>#include <numeric>#include <set>#include <string>#define INF 0x3f3f3f3ftypedef long long LL;using namespace std;bool sushu(int n){ int i; if(n<2) return false; for (i=2;i*i<=n;i++) { if (n%i==0) return false; } return true;}int main (){ int x,y; while (~scanf ("%d%d",&x,&y)&&(x||y)){ int i; for (i=x;i<=y;i++) { if (!sushu(i*i+i+41)) {printf ("Sorry\n");break;} } if (i==y+1) printf ("OK\n"); } return 0;}
0 0
- hdu 2012 素数判定
- HDU 2012 素数判定
- hdu 2012 素数判定
- HDU:2012素数判定
- hdu 2012 素数判定
- hdu 2012 素数判定
- hdu-2012-素数判定
- HDU 2012 素数判定
- HDU 2012 素数判定
- [hdu 2012] 素数判定
- HDU 2012 素数判定
- HDU 2012 素数判定
- HDU 2012 素数判定
- HDU 2012 素数判定
- hdu 2012 素数判定
- HDU 2012 --- 素数判定
- HDU 2012 判定素数
- 素数判定 HDU 2012
- Git操作指南
- JQuery -- this 和 $(this) 的区别
- Action 中获取表单数据的三种方式
- 中山大学转专业过程及心得
- urllib2 实现简单爬取12306网站
- hdu 2012 素数判定
- Python高级数据处理与可视化(三)---- Matplotlib图像属性控制
- 2007年北理复试上机题
- C++之继承篇
- socket.io简单笔记1
- 简单的拍照dome
- Spring 源码分析(一) —— 迈向Spring之路
- 80. Remove Duplicates from Sorted Array II
- python遍历文件