杭电oj 2012

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 1 0 0

看不题意

///*
//看不懂题目  42不是素数啊 
//
//
//*/ 
//
//#include <cstdio>
//
//int IS(int a){
//	int s = a*a+a+41;
//	for(int i = 2;i <= s/2;i++)
//	if(s%i == 0)
//		return 0;
//	return 1;
//}
//
//int main(){
//	int n,m;
//	int sum = 0;
//	//scanf("%d %d",&n,&m);
//	while(scanf("%d %d",&n,&m),n || m){
//	
//		for(int i=n;i<=m;i++)
//		{
//			if(IS(i))
//				sum++;
//		}
//		if(sum == m-n+1)
//			printf("OK\n");
//		else
//			printf("Sorry\n");
//	}
//	
//	return 0;
//}





#include<cstdio>
#include<cmath>
int main() {
	int x,y,flag = 0;
	while(scanf("%d%d",&x,&y),x||y) {

		flag = 1;
		for(int i = x; i<=y; ++i) {
			int t = i*i+i+41,j;
			for(j = 2; j <= int(sqrt(t)); ++j)
				if(t%j == 0) {
					flag = 0;
					break;
				}
			if(flag == 0)break;

		}
		if(!flag)
			printf("Sorry\n");
		else
			printf("OK\n");

	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qing_feng__/article/details/86735436