hpuacm 第一次省赛选拔



The world famous scientist Innokentiy has just synthesized the potion of immortality. Unfortunately, he put the flask with this potion on the shelf where most dangerous poisons of all time were kept. Now there are n flasks on this shelf, and the scientist has no idea which of them contains the potion of immortality.

Fortunately, Innokentiy has an infinite amount of rabbits. But the scientist doesn't know how exactly these potions affect rabbits. There is the only thing he knows for sure. If rabbit tastes exactly k potions from the flasks on the shelf, it will survive if there was the immortality potion among them and die otherwise. If rabbit tastes the number of potions different from k, the result will be absolutely unpredictable, so the scientist won't make such experiments no matter what.

The scientist intends to minimize the amount of lost rabbits while searching for the potion of immortality. You should determine how many rabbits he has to sacrifice in the worst case.

Input

The only line contains two integers separated by space — n and k (1 ≤ n ≤ 2000, 1 ≤ k ≤ n) — the number of flasks on the Innokentiy's shelf and the number of potions Innokentiy will give to a single rabbit to taste.

Output

If the scientist cannot determine which flusk contains the potion of immortality, output «-1». Otherwise, output a single integer — the minimal number of rabbits that Innokentiy will sacrifice in the worst case while searching for the potion of immortality.

Example
Input
3 2
Output
1
Input
4 2
Output
2
题意:有一个科学家创造出不死药(好腻害QAQ),不幸的是他把装有不死药的烧瓶和装有毒药的烧瓶混在一起,现在他要将其找出来,他有一群兔子,n个烧瓶,他一次喂一只兔子k个药水,如果这k个药水中含有不死药,兔子就不会死,否则就会死,现在要找出在最坏情况下损失的最小兔子数,当科学家无法在一次试验中喂兔子k瓶,实验就会停止。
思路:注意不是一次就将药水喂完,也就是说可以重复使用(就错在这里了QAQ),那么就可以推出和实验次数有关,先考虑特殊情况:n=k时肯定无法确定,输出-1,n=1时输出0,k=1时输出n-1,当余数为1或0,输出的是n/k,否则为n/k+1;可以多推几组数据试试。。
下面附上代码:
#include<cstdio>
int main()
{
	int a,b;
	while(~scanf("%d %d",&a,&b))
	{
		
		if(a==1) printf("0\n");
		else if(a==b) printf("-1\n");
		else if(b==1) printf("%d\n",a-1);
		else 
		{
			int m=a/b;
			if(a%b==0||a%b==1) printf("%d\n",m);
			else printf("%d\n",m+1);
		}
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值