您的位置:首页 > 其它

HDU杭电1795 The least one

2015-08-01 18:26 483 查看
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




//题目大意:求离给的数最近的素数

#include<stdio.h>
#include<string.h>
int a[100050];
void IsPrime()
{
	a[1]=1;
	a[0]=1;
	int i,j;
	for(i=2;i<100000;++i)
	{
		for(j=2*i;j<100000;j+=i)
		{
			a[j]=1;
		}
	}
}
int main()
{	
	
	int t,n,i;
	IsPrime();
	scanf("%d",&t);	
	while(t--)
	{
		scanf("%d",&n);
		for(i=n+1;i<100000;++i)
		{
			if(!a[i])
			{
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: