HDOJ 2012 素数判定
2017-05-03 12:52
169 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=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
Sample Output
OK
题解
#include <stdio.h>
int main()
{
int m, n;
int x[] =
{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1
};
while (scanf("%d%d", &m, &n), m || n)
{
for (m += 39, n += 39; x[m] && m <= n ; m++);
{
puts(m > n ? "OK" : "Sorry");
}
}
return 0;
}
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
Sample Output
OK
题解
#include <stdio.h>
int main()
{
int m, n;
int x[] =
{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1
};
while (scanf("%d%d", &m, &n), m || n)
{
for (m += 39, n += 39; x[m] && m <= n ; m++);
{
puts(m > n ? "OK" : "Sorry");
}
}
return 0;
}
相关文章推荐
- HDOJ 【C】 2012 素数判定
- hdoj 素数判定 2012 (素数打表)
- hdoj 2012 素数判定
- Hdoj 2012 素数判定
- HDOJ2012素数判定
- hdoj2012(java)素数判定
- HDOJ--2012素数判定
- HDOJ-2012 素数判定
- HDOJ 2012 素数判定
- hdoj2012_素数判定
- hdoj_2012 素数判定
- HDOJ 2012-素数判定
- HDOJ-2012 素数判定
- HDOJ 2012 素数判定
- HDOJ 2012 素数判定
- HDOJ 2012 素数判定
- hdoj.2012 素数判定 20140722
- hdoj2012素数判定
- C++ hdoj 2012 素数判定
- hdoj 2012 素数判定 (打表)