The least one
2015-08-20 19:11
211 查看
[align=left]Problem Description[/align]
[align=left][/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]
[align=left] [/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]
[align=left] [/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]
[align=left] [/align]
[align=left]Sample Output[/align]
5
[align=left]11[/align]
题意:找与Q离得最近的素数
[align=left][/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]
[align=left] [/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]
[align=left] [/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]
[align=left] [/align]
2 3 7
[align=left]Sample Output[/align]
5
[align=left]11[/align]
题意:找与Q离得最近的素数
#include<stdio.h> #include<math.h> #include<string.h> int is(int x) { if(x==0||x==1) return 0; else { int c; c=sqrt(x*1.0); for(int i=2;i<=c;i++) { if(x%i==0) return 0; //return 1; } return 1; } } int main() { int n; scanf("%d",&n); while(n--) { int Q,i; scanf("%d",&Q); for(i=Q+1;;i++) { if(is(i)) { printf("%d\n",i); break; } } } return 0; }
相关文章推荐
- HDU1698 Just a Hook
- 矩阵理解(三)
- 【HDOJ 1005】 CRB and His Birthday
- ubuntu中装mysql
- 局域网YUM源中添加rpm包
- 三国游戏开发策略
- 【机房收费系统】VB中增删改查实践探索
- 理解矩阵(二)
- 字符串替换空格:实现函数"we are happy."-->>"we%20are%20happy."
- 以Oracle数据库为目标的数据库进阶(一)
- HDU 5344 MZL's xor
- poj3159(spfa)
- POJ 1789 Truck History
- 【Linux系统编程】 浅谈标准I/O缓冲区
- 如何用Maven创建web项目(具体步骤)
- 懂代码设计更容易!PS CC与前端那些事
- oracle_角色
- Linux 开机自动挂载windows分区
- date - 显示、修改系统日期时间
- MongoDB 3.0 for java (一、java连接MongoDB)