【HDU - 2012】素数判定(水题,数论,打表)

题干:

 

解题报告:

 

AC代码1:

#include<bits/stdc++.h>
#define MAX 10000//求MAX范围内的素数 
using namespace std;  long long su[MAX],cnt;  
bool isprime[MAX];  
void prime()  
{  cnt=1;  memset(isprime,1,sizeof(isprime)); isprime[0]=isprime[1]=0;for(long long i=2;i<=MAX;i++)  {  if(isprime[i]) {su[cnt++]=i; } for(long long j=1;j<cnt&&su[j]*i<MAX;j++)  {  isprime[su[j]*i]=0;}  }  
}  
int main()  
{  prime();  int tmp=0;int x,y,flag; while(~scanf("%d %d",&x,&y) ) {if(x==0 && y == 0) break;flag = 0;for(int i = x; i<=y; i++) {tmp = i*i+i+41;if(!isprime[tmp] ) {flag = 1;break;}}flag == 1 ? printf("Sorry\n") : printf("OK\n");}return 0;  
}  

AC代码2:

#include<stdio.h>
#include<math.h>
int isPrime(int x);
int main()
{int i,flag; int x,y;while(scanf("%d",&x)!=EOF){scanf("%d",&y);flag=1;if(x==0&&y==0){break;}else{for(i=x;i<=y;i++){if(isPrime(i*i+i+41)==0){flag=0;break;}}}if(flag==1){printf("OK\n");}else{printf("Sorry\n");}}return 0 ;
}
int isPrime(int x){int i,flag=1;for(i=2;i<sqrt(x);i++){	if(x%i==0){flag=0;break;}}return flag;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441225.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【POJ - 3048】Max Factor (数论,打表,水题)

题干&#xff1a; To improve the organization of his farm, Farmer John labels each of his N (1 < N < 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the cows interpret some serial numbers as better …

伺服电机停的时候会冲一下_造成伺服电机抖动的原因竟然是它!内附解决方法...

伺服电机(servo motor )是指在伺服系统中控制机械元件运转的发动机&#xff0c;是一种补助马达间接变速装置。它可使控制速度&#xff0c;位置精度非常准确&#xff0c;可以将电压信号转化为转矩和转速以驱动控制对象。伺服电机转子转速受输入信号控制&#xff0c;并能快速反应…

系统备份是对计算机硬件进行维户吗,计算机系统维护毕业论文_精品.doc

计算机系统维护毕业论文_精品计算机系统维护毕业论文2. Easyrecovery153. 驱动精灵17第三章&#xff1a;Win 7系统的使用和维护181. 利用Win 7操作系统自带的工具对系统进行维护和优化182. 利用专用的工具软件对Win 7系统进行维护和优化192.1 Win 7优化大师202.2 魔方213. 注册…

【 HDU - 5363】Key Set(水题,快速幂,组合数学)

题干&#xff1a; soda has a set SS with nn integers {1,2,…,n}{1,2,…,n}. A set is called key set if the sum of integers in the set is an even number. He wants to know how many nonempty subsets of SS are key set. Input There are multiple test cases. The…

ajax 更新模型数据_DuangDuangDuang,重点来啦!高薪全靠它——百战Web前端课程更新03.11...

百战程序员九大专业运营&#xff0c;周周有课程更新&#xff0c;保持行业领先。本次更新课程Web前端第三十阶段经典面试题解析章节1—5及课程资料。本次更新可谓是诚意满满&#xff0c;针对市场面试需要&#xff0c;总结经典面试题集&#xff0c;为你揭开企业技术要求的神秘面纱…

河南省高考让不让带计算机,河南高考2018严禁携带的东西有哪些?这种衣服不能进考场...

近日&#xff0c;河南省开启高考“严控”模式&#xff0c;将依法从严治考&#xff0c;关怀服务考生&#xff0c;对任何破坏高考安全工作的行为“零容忍”。带金属的鞋带、鞋眼、鞋底&#xff0c;带金属挂钩和钢圈的内衣、腰带、裤子挂钩、衣扣通通不能进考场&#xff01;  快…

【POJ - 2262】Goldbach's Conjecture (数论,哥德巴赫猜想,知识点结论)

题干&#xff1a; In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture: Every even number greater than 4 can be written as the sum of two odd prime numbers.For example: 8 …

msg计算机指令怎样用,WIN7里使用msg命令发送消息失败

使用服务&#xff1a;WIN7里使用msg命令发送消息一、msg语法MSG {username | sessionname | sessionid | filename | *}[/SERVER:servername] [/TIME:seconds] [/V] [/W] [message]username 标识指定的用户名。sessionname 会话名。sessionid 会话…

combox 增加请选择_娱乐测试:选择四种花束中的一种,测试你对婚姻的看法

阅读本文前&#xff0c;请您先点击上面的“落落天使”&#xff0c;再点击“关注”&#xff0c;这样您就可以继续免费收到文章了。每天都有分享&#xff0c;完全是免费订阅&#xff0c;请放心关注。 …

【POJ - 2909 】Goldbach's Conjecture (哥德巴赫猜想,数论,知识点结论)

题干&#xff1a; For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n p1 p2 This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. …

计算机突然断电恢复供电后,电脑突然断电的坏处有哪些?

对于经常使用计算机进行办公的用户而言&#xff0c;最可怕的事情是计算机在保存文件之前突然断电关机。但是&#xff0c;这对于计算机本身根本不是问题&#xff0c;只要计算机能够正常运行。但是&#xff0c;如果断电导致以下任何一种情况&#xff0c;则需要小心&#xff01;1、…

python函数实例解析_python支持返回函数的实例解析

这篇文章主要介绍了python支持返回函数的实例解析,小编觉得挺不错的&#xff0c;现在分享给大家&#xff0c;也给大家做个参考。一起跟随小编过来看看吧最近接触python,看到了python中返回函数的概念&#xff0c;以前只接触过函数返回值&#xff0c;比如python就可以返回int,st…

【CodeForces - 260D】Black and White Tree (思维构造,猜结论,细节,构造一棵树)

题干&#xff1a; The board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesnt contain any cycles. Each node of the graph is painted black or white in such a mann…

手游 自建服务器,英灵神殿自己搭建服务器怎么弄

英灵神殿是一款冒险生存类游戏&#xff0c;在英灵神殿游戏中小伙伴要自己搭建服务器才能玩&#xff0c;那么要怎么搭建&#xff0c;有什么技巧吗?接下来和小编一起来看看吧!Valheim英灵神殿服务器搭建技巧第一步&#xff1a;SteamCMD和安装内容从这里下载SteamCMD。将其提取到…

描写火车站场景_关于描写火车站的句子

关于描写火车站的句子关于描写火车站的句子所以至今&#xff0c;我仍很爱乘火车&#xff0c;卧铺&#xff0c;靠在枕头上看书&#xff0c;沉沉睡去&#xff0c;听铁轨一层一层的荡漾&#xff0c;在记忆中昏暗地穿行&#xff0c;如果我爱谁&#xff0c;我们一定会乘火车去很远的…

【POJ - 1463】Strategic game (树上最小点覆盖,树形dp)

题干&#xff1a; Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which form a tree…

vue css自定义标签,Vue如何使用CSS自定义变量

目录在 css 自定义变量的功能以及出来许久了&#xff0c;但实际开发中大家使用并不多。归其原因是因为 less、sass 等预处理器已经拥有定义变量的功能&#xff0c;以及Vue、react很方便设置 style 样式&#xff0c;大家可能觉得使用 css 定义变量不方便且没必要。实则不然举个最…

【CodeForces - 260A】Adding Digits (思维构造)

题干&#xff1a; Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times. One operation of lengthening a number means adding exactly one digit to the number (in the…

人工智能在fpga的具体应用_人工智能带动了FPGA的发展

未来几年&#xff0c;人工智能芯片的需求将急剧上升。联合市场研究公司(Allied Market Research)预估&#xff0c;未来5年&#xff0c;人工智能芯片的需求将以每年近50&#xff05;的速度增长&#xff0c;因为该技术将在汽车、医疗保健等多个领域得到广泛应用。Xilinx深知其中存…

恐怖黎明稳定服务器,恐怖黎明新人联机图文教程 怎么联机-游侠网

恐怖黎明怎么联机?不少玩家想体验联机&#xff0c;但是不知道方法&#xff0c;小编这里给大家带来了新人联机图文教程&#xff0c;不会的萌新来学习下吧。联机图文教程:A1 联机&#xff1a;因为gd(grimdawn)没有自己的战网平台(就是专供联机玩的专职服务器 server)&#xff0c…