codeforces Gym 100187 A. 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 aren 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 exactlyk 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 fromk, 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.

Sample test(s)
Input
3 2
Output
1
Input
4 2
Output
2

题意:n瓶药,有1瓶是好药,其他都是毒药,一只兔子一次喝k瓶,问在最坏的情况下最少死多少只兔子

思路:很显然是(n-1)/k只,但是要处理一下特殊情况,n=1和n=k的时候

刚开始看以为是1只兔子喝一瓶药,同时k个兔子喝k瓶药,问死多少只兔子,后来对着样例看了看,原来理解错了。。。汗。。。


ac代码:
#include
#include
#include
#include
#include
#include
#include
#define MAXN 1010000
#define LL long long
#define ll __int64
#include
#include
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
using namespace std;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
ll powmod(ll a,LL b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
//head
int main()
{
	int n,k;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		if(n==1)
		printf("0\n");
		else if(n==k)
		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;
}


你可能感兴趣的:(数学问题)