杭电 1795 The least one
2015-08-01 20:00
405 查看
The least one
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 492 Accepted Submission(s):
184
[align=left]Problem Description[/align]
In the RPG game “go back ice age”(I decide to develop
the game after my undergraduate education), all heros have their own respected
value, and the skill of killing monsters is defined as the following rule: one
hero can kill the monstrers whose respected values are smaller then himself and
the two respected values has none common factor but 1, so the skill is the same
as the number of the monsters he can kill. Now each kind of value of the
monsters come. And your hero have to kill at least M ones. To minimize the
damage of the battle, you should dispatch a hero with minimal respected value.
Which hero will you dispatch ? There are Q battles, in each battle, for i from 1
to Q, and your hero should kill Mi ones at least. You have all kind of heros
with different respected values, and the values(heros’ and monsters’) are
positive.
[align=left]Input[/align]
The first line has one integer Q, then Q lines
follow. In the Q lines there is an integer Mi, 0<Q<=1000000,
0<Mi<=10000.
[align=left]Output[/align]
For each case, there are Q results, in each result,
you should output the value of the hero you will dispatch to complete the
task.
[align=left]Sample Input[/align]
2
3
7
[align=left]Sample Output[/align]
5
11
题意:就是求比所给数据大的最近的素数
#include<stdio.h> #include<string.h> #define MAX 10010 int su[MAX]; void prime() { int i,j; memset(su,0,sizeof(su)); for(i=2;i<MAX;i++) { if(!su[i]) { for(j=i*2;j<MAX;j+=i) su[j]=1; } } su[1]=1; } int main() { int t,n,m,j,i; scanf("%d",&t); prime(); while(t--) { scanf("%d",&n); for(i=n+1;i<MAX;i++) { if(su[i]==0) { printf("%d\n",i); break; } } } return 0; }
相关文章推荐
- ora 12560 协议适配器错误
- Android Context与GetApplicationContext的区别及使用
- 黑马程序员——数组
- swift学习之函数的参数命名
- 对mysql多表查询的理解
- 公平锁 轻量锁
- HashMap 与 Hashtable对比
- SELinux 的开启和关闭
- 如何查看物理CPU和逻辑CPU
- win10升级后 IE 火狐 谷歌浏览器 不能上网 解决办法
- poj 3370/2356 鸽巢原理
- python 去扫域名是否被注册
- UI02_UIButton和UITextField
- Leetcode #242 Valid Anagram
- SELinux 的开启和关闭
- 黑马程序员——流程控制
- 学习编程的七个阶段
- EFCode First 导航属性
- SELinux 的开启和关闭
- Android开发----音乐播放器(扫描本地音乐)