Gym100187A Potion of Immortality(水题+想不懂)

A. Potion of Immortality
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ≤ 20001 ≤ 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.

Examples
input
3 2
output
1
input
4 2
output
2

题意:有n瓶药放在架子上,其中有一瓶是不死药,其他的都为毒药,要判断哪一瓶为毒药,用兔子来试药,每次让它喝其中的k瓶(可以重复喝),如果兔子活着,说明喝的k瓶中有不死药,反之则死亡,问在最坏的情况下死亡的兔子最少数,如果不能试出来,输出"-1".

首先是最坏的情况用最少的兔子,说明是在最坏的情况下来的,每次试药都有兔子死,例如有15瓶(1-15号),每次喝4瓶,第一次喝(1-4)瓶死,第二次喝(5-8)瓶死,第三次喝(9-12)瓶死,此时可确定不死药在13-15瓶中,接下来就是最少的了,假如第15瓶为不死药,那么用第四只兔子让它喝13,14和1-12中的两瓶。

当n=17 k=4时,喝忘前四次就知道了。

#include   
#include   
using namespace std;  
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	if(n==1)
	   printf("0\n");
	else if(k==n)
	   printf("-1\n");
	else if(k==1)
	   printf("%d\n",n-1);
	else
	{
		if(n%k==0||n%k==1)
	       printf("%d\n",n/k);
		else
		   printf("%d\n",n/k+1); 
	} 
	return 0;	   
}


你可能感兴趣的:(Gym100187A Potion of Immortality(水题+想不懂))