杭电1795-The last one

The least one
Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 445    Accepted Submission(s): 159




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


//杭电1795:The last one
// 题目大意:输入一个数 M,求大于M且离M最近的素数; 
//解题思路:
//首先要写一个函数用来判断素数 ,假设输入一个数 M ,令 J=M+1;从M+1开始依次经行素数判断,
//当从M+1找到第一个素数时就是要找的最接近M的最小素数;打印输出,用break跳出循环; 
#include<stdio.h>
#include<math.h>
int sushu(int x){
	int i,a;
	a=sqrt(x);
	for(i=2;i<=a;i++)
	{
		if(x%i==0)
		 return 0;
		
	}
	return 1;	
}
int main()
{
	int t,m,j;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&m);
		j=m+1;
		while(m--)
		{
			if(sushu(j))
			{
			 printf("%d\n",j);
			 break;
			}
			j++;
		}
	}
    return 0;	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bokzmm

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值