杭电1795--The least one

The least one

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 534    Accepted Submission(s):
203

Problem Description

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.

Input

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.

Output

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.

Sample Input

2

3

7

Sample Output

5

11

Author

wangye

Source

2008
“Insigma International Cup” Zhejiang Collegiate Programming Contest - Warm Up(4)

Recommend

wangye   |   We have carefully selected several similar
problems for you:  1793 1796 1797 1794 1798

题意:杀怪兽游戏,英雄的能力要大于怪兽;并且两者能力都为质数,综合可得所求答案为 大于给出数的最小素数;

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 using namespace std;
 5 int sieve[10010];
 6 void is_prime()
 7 {
 8     memset(sieve, 0, sizeof(sieve));
 9     for(int i = 2; i<10010; i++)
10     {
11         if(sieve[i] == 0)
12         {
13             for(int j = 2 * i; j<10010; j+=i)
14                 sieve[j]=1;
15         }
16     }
17 }
18 int main()
19 {
20     int m, t, i;
21     scanf("%d", &t);
22     is_prime();
23     while(t--)
24     {
25         scanf("%d", &m);
26         for(i=m+1; i<10010; i++)
27             if(sieve[i]==0)
28                 break;
29         printf("%d\n", i);
30     }
31     return 0;
32 }
时间: 2024-08-10 22:32:48

杭电1795--The least one的相关文章

杭电 1795 The least one

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 Problem Description In the RPG game “go back ice age”(I decide to develop the game after my under

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

hdu 1016 Prime Ring Problem DFS解法 纪念我在杭电的第一百题

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29577    Accepted Submission(s): 13188 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

一个人的旅行 HDU杭电2066【dijkstra算法】

http://acm.hdu.edu.cn/showproblem.php?pid=2066 Problem Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景--草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯粹看雪景,去巴黎喝咖啡写信,去北京探望孟姜女--眼看寒假就快到了,这么一大段时间,可不

杭电1162--Eddy&#39;s picture(Prim()算法)

Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8070    Accepted Submission(s): 4084 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to b

杭电1276--士兵队列训练问题

士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4605    Accepted Submission(s): 2148 Problem Description 某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行

杭电1272 并查集找环+判断连通

杭电1272 并查集找环+判断连通 E - E Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1272 Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B

杭电ACM Java实现样例

若使用Java求解杭电ACM,答案提交必须注意两点: 1.类名一定得是Main,否则服务器无法编译: 2.必须用while进行输入判断. 以1000题测试题为例,代码如下: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); while(scan.hasNextInt()) { int a=scan.n