码迷,mamicode.com
首页 > 其他好文 > 详细

杭电1795--The least one

时间:2015-08-02 06:22:20      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

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
 

 

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 }

 

 

杭电1795--The least one

标签:

原文地址:http://www.cnblogs.com/fengshun/p/4695006.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!