HPU-ACM暑期培训第2周14级个人赛:Problem I The least one HDU 1795

本文介绍了一个游戏编程中的数学挑战问题,玩家需要派遣具有特定数值的英雄角色来战胜怪物,确保所选英雄的数值与怪物数值互质。文章通过一个示例问题展示了如何找到最小的质数英雄数值以完成任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem I

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

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
 
题意:
          有一个游戏,游戏中的英雄能够将比他能量少的怪兽杀掉并且要求这个怪兽的能量与英雄的能量之间没有公因数,而且一个英雄至少可以杀掉输入的怪兽的能量值的个数的怪
 
兽,也就是能将小于等于输入怪兽能量值小的怪兽全杀掉,又因为要求要求这个怪兽的能量与英雄的能量之间没有公因数,所以要求英雄的能量值必须是素数,并且比怪兽的能量值
 
要大!注:怪兽的能量值可以不是素数!
AC-code:
#include<cstdio>
#include<cmath>
int main()
{
	int n,m,j,k;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&m);
		for(j=m+1;j<10100;j++)
		{
			int flag=0;
			for(k=2;k<=(int)sqrt(j);k++)
			{
				if(j%k==0)
				{
					flag=1;
					break;
				}
			}
			if(!flag)
			{
				printf("%d\n",j);
				break;
			}	
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值