The least one
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 543 Accepted Submission(s): 209
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
#include<stdio.h>
#include<math.h>
int issushu(int n)
{ int i,t=1;
for(i=2;i<=sqrt(n);i++)
{ if(n%i==0)
{
t=0;
break;
}
}
if(t)
return 1;
else
return 0;
}
int main()
{ int m,n;
scanf("%d",&n);
while(n--)
{ scanf("%d",&m);
for(int i=m+1; ;i++)
{ if(issushu(i))
{ printf("%d\n",i);
break;
}
}
}
return 0;
}
Sample Output
5 11
Author
wangye
Source
Recommend
//这道题主要是要能够读懂题的意思:给你一个数,你要找到比它大的数,注意素数的判断,不能循环到n,否则会超时的,只需要循环到根号下根号下你,就行,参考代码如下: