天天看點

FZU 1150 Farmer Bill's Problem

Description

Peter has n cigarettes. He smokes them one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette.

How many cigarettes can Peter have?

Input

Input is a sequence of lines. Each line contains two integer numbers giving the values of n and k.

Output

4 3

10 3

100 5

5

14

124

簡單數學問題

#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=1000005;
LL T,n,m;

int main()
{
	while (~scanf("%lld%lld",&n,&m))
	{
		T=n;
		while (n>=m)
		{
			T+=n/m;
			n=n/m+n%m;
		}
		printf("%lld\n",T);
	}
	return 0;
}