素数判定

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 68870    Accepted Submission(s): 23862

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
 
Author
lcy

解题报告:

当输入都为0时,要写成x==0 && y==0,不要写成x==y==0

 #include<stdio.h>
#include<math.h>
int is_prime(int temp)
{
int m = (int)sqrt(double(temp));
for(int i = ; i <= m; i++)
{
if(temp % i == )
return ;
}
return ;
}
int main()
{
int x, y, temp, i;
while(scanf("%d%d", &x, &y) == )
{
if(x == && y == )
continue;
for(i = x; i <= y; i++)
{
temp = i*i+i+;
if(!is_prime(temp))
break;
}
if(i == y+)
printf("OK\n");
else
printf("Sorry\n");
}
return ;
}

HDOJ2012素数判定的更多相关文章

  1. FZU 1649 Prime number or not米勒拉宾大素数判定方法。

    C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  2. algorithm@ 大素数判定和大整数质因数分解

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  3. Codevs 1702 素数判定 2(Fermat定理)

    1702 素数判定 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 传送门 题目描述 Description 一个数,他是素数么? 设他为P满足(P< ...

  4. hdu 2012 素数判定 Miller_Rabbin

    素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. 素数判定 AC 杭电

    素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  6. 杭电ACM 素数判定

    素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  7. 数学#素数判定Miller_Rabin+大数因数分解Pollard_rho算法 POJ 1811&2429

    素数判定Miller_Rabin算法详解: http://blog.csdn.net/maxichu/article/details/45458569 大数因数分解Pollard_rho算法详解: h ...

  8. 多项式求和,素数判定 HDU2011.2012

    HDU 2011:多项式求和 Description 多项式的描述如下: 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ... 现在请你求出该多项式的前n项的和.   Input ...

  9. Miller-Rabin算法 codevs 1702 素数判定 2

    转载自:http://www.dxmtb.com/blog/miller-rabbin/ 普通的素数测试我们有O(√ n)的试除算法.事实上,我们有O(slog³n)的算法. 定理一:假如p是质数,且 ...

随机推荐

  1. ACE的包装器

    ACE大量运用包装器模式,以期改变面向过程的系统API可视性以及错误处理较难的情况 包装器在若干场合能极大简化代码量,甚至是编码过程 比如ACE_Thread_Mutex 对象创建会自动初始化,很开心 ...

  2. 使用IIS Express

    1.IIS Express 概述 IIS Express是一个微软推出的一款免费,且小型.轻量特别适合ASP.NET开发人员使用的Web开发服务器.在没有IIS Express之前,开发人员只能使用下 ...

  3. hadoop2.1.0编译安装教程

    由于现在hadoop2.0还处于beta版本,在apache官方网站上发布的beta版本中只有编译好的32bit可用,如果你直接下载安装在64bit的linux系统的机器上,运行会报一个INFO ut ...

  4. list删除操作 java.util.ConcurrentModificationException

    首先大家先看一段代码: public static void main(String[] args) { List<String> listStr = new ArrayList<S ...

  5. mysql case when 条件过滤

    [1].[代码] 使用CASE WHEN进行字符串替换处理 跳至 [1] [2] [3] [4] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2 ...

  6. HTML输出 一 控制列背景颜色

    #将需要读取的域名和端口列表保存在名为ports01.txt.ports02的文件中,文件与脚本位于相同目录下$CurrentPath = $MyInvocation.MyCommand.Path.s ...

  7. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  8. DOS命令生成文件列表

    DOS命令窗口,生成文件列表命令格式:dir xmlFiles /b >list.txt dir 文件列表相关命令 xmlFiles 待生成文件所在文件夹,在dos命令窗口根目录下,省略前缀.别 ...

  9. Android-L-Samples

    https://github.com/s3xy4ngyc/Android-L-Samples

  10. [MODx] 3. Working with chunks, TV, Category

    1. Add chunk: For example, replace the header by using chunk. Usage: [[$chunk_name]] Cut all the hea ...