HDU 2012 (水)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2012
题目大意:给你段连续数字,判断每个数字带入函数 n^2+n+41 是否都为素数,是输入OK,否则输出Sorry
解题思路:
写一个判断素数的函数,然后设置一个标志 p 同时遍历这段数字,如果不是素数标志 p 改变一下病并输出 Sorry, 最后遍历结束如果标志未改变,就输出OK
判断 num 是否为素数:如果大于 2 小于等于 √num 数中没有可以整除 num 的数就是素数,否则是合数,1 既不是素数也不是合数
数论基础:任何大于1的整数均可被表示成一串唯一素数之乘积
代码:
#include<iostream>
#include<cmath>
#include<iomanip>
//#include<algorithm>
using namespace std;
int num;
int prime(int x)
{
num = x * x + x + ;
if(num == )
return ;
// for(int i = 2; i < num; i ++)
// {
// if(num % i == 0)
// return 0;
// }
for(int i = ; i <= sqrt(num); i ++)
{
if(num % i == )
return ;
}
return ;
}
int main()
{
int x, y;
int p;
while(cin >> x >> y && (x || y))
{
p = ;
for(int i = x; i <= y; i ++)
{
if(!prime(i))
{
p = ;
cout << "Sorry" << endl;
break;
}
}
if(p == )
cout << "OK" << endl;
}
}
HDU 2012 (水)的更多相关文章
- HDU 2012 FZU 1756关于素数的一些水题
HDU 2012 素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU-1042-N!(Java大法好 && HDU大数水题)
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Subm ...
- hdu 4464 水
http://acm.hdu.edu.cn/showproblem.php?pid=4464 现场赛总会有水题,这就是最水的一道,预计也就是能当高校的上机题,保研用,呵呵~~~ #include &l ...
- HDU 2012 素数判定
http://acm.hdu.edu.cn/showproblem.php?pid=2012 Problem Description 对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括 ...
- HDU 5391 水题。
E - 5 Time Limit:1500MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- hdu 1544 水题
水题 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #i ...
- hdu 3357 水题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357 #include <cstdio> #include <cmath> # ...
- hdu 5007 水 弦
http://acm.hdu.edu.cn/showproblem.php?pid=5007 纯粹的联系String的substr 什么时候substr拦截比写短话 string te; int n; ...
- Tickets HDU - 1260 水DP
HDU - 1260 现在有n个人要买电影票,如果知道每个人单独买票花费的时间, 还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. 直接dp就行,注意下输出和初始化 每次从dp[i-1 ...
随机推荐
- java面试题(一年工作经验)的心得
看面试题 正常人第一步肯定都会看面试题,我也不例外,在看的过程中,我发现有些文章写的不错,对我帮助不小值得推荐,如下: Java面试题全集(上) 很多基础的东西,建议先看. 各大公司Java后端开发面 ...
- (一)微信小程序:实现引导页
基本目录结构 index目录下文件操作步骤 1.针对index.wxml <!--index.wxml--> <view class="index-container&qu ...
- 关于php抑错方法
在循环里,如果@不能用的话,就使用try catch,是可以的
- mysql---3种常用引擎 和优点
- QtConcurrent::run() 只能运行参数个数不超过5的函数
有时不得不看源码 qtconcurrentrun.h template <typename T, typename Param1, typename Arg1, typename Param2, ...
- Spring5参考指南:Environment
文章目录 Profiles PropertySource 使用@PropertySource Spring的Environment接口有两个关键的作用:1. Profile, 2.properties ...
- XEP-0199 XMPP Ping
原文来自:https://xmpp.org/extensions/xep-0199.html,只翻译了技术方面的内容. 摘要:这个规范定义了一个通过XML流发送应用级别pings的XMPP扩展协议.这 ...
- 配置IIS5.5/6.0 支持 Silverlight
在安装完Silverlight1.1 Alpha后,要使自己的IIS服务器支持Silverlight的浏览还需要配置一下IIS网站的 Http头->MIME映射添加内容如下:扩展名 ...
- ajax 技术
ajax 技术 $.ajax({ url:"", type:'GET', success:function(data){ console.log(data); }, error:f ...
- 数学--数论--HDU 2582 F(N) 暴力打表找规律
This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gc ...