Little Bobby loves chocolate.  He frequently goes to his favorite $5\text{&}10$ store, Penny Auntie, to buy them.  They are having a promotion at Penny Auntie.  If Bobby saves enough wrappers, he can turn them in for a free chocolate.  

Example 

$n=15$ 

$c=3$ 

$m=2$  

He has $15$ to spend, bars cost $3$, and he can turn in $2$ wrappers to receive another bar.  Initially, he buys $5$ bars and has $5$ wrappers after eating them.  He turns in $4$ of them, leaving him with $1$, for $2$ more bars.  After eating those two, he has $3$ wrappers, turns in $2$ leaving him with $1$ wrapper and his new bar.  Once he eats that one, he has $2$ wrappers and turns them in for another bar.  After eating that one, he only has $1$ wrapper, and his feast ends.  Overall, he has eaten $5+2+1+1=9$ bars.    

Function Description   

Complete the chocolateFeast function in the editor below.  

chocolateFeast has the following parameter(s):  

int n: Bobby's initial amount of money  
int c: the cost of a chocolate bar  
int m: the number of wrappers he can turn in for a free bar  

Returns  

int: the number of chocolates Bobby can eat after taking full advantage of the promotion

Note: Little Bobby will always turn in his wrappers if he has enough to get a free chocolate.

Input Format

The first line contains an integer, $\boldsymbol{\boldsymbol{t}}$, the number of test cases to analyze. 

Each of the next $\boldsymbol{\boldsymbol{t}}$ lines contains three space-separated integers:  $n$, $\textbf{C}$, and $m$.  They represent money to spend, cost of a chocolate, and the number of wrappers he can turn in for a free chocolate. 

Constraints

$1\leq t\leq1000$  
$2\leq n\leq10^5$  
$1\leq c\leq n$  
$2\leq m\leq n$  

Sample Input
STDIN   Function
-----   --------
3       t = 3 (test cases)
10 2 5  n = 10, c = 2, m = 5 (first test case)
12 4 4  n = 12, c = 4, m = 4 (second test case)
6 2 2   n = 6,  c = 2, m = 2 (third test case)

Sample Output
6
3
5

Explanation

Bobby makes the following $3$ trips to the store:

He spends $10$ on $5$ chocolates at $2$ apiece. He then eats them and exchanges all $5$ wrappers to get $1$ more. He eats $\boldsymbol{6}$ chocolates.
He spends his $12$ on $3$ chocolates at $4$ apiece.  He has $3$ wrappers, but needs $4$ to trade for his next chocolate. He eats $3$ chocolates.  
He spends $\boldsymbol{6}$ on $3$ chocolates at $2$ apiece. He then exchanges $2$ of the $3$ wrappers for $1$ additional piece. Next, he uses his third leftover chocolate wrapper from his initial purchase with the wrapper from his trade-in to do a second trade-in for $1$ more piece. At this point he has $1$ wrapper left, which is not enough to perform another trade-in. He eats $5$ chocolates.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(N, C, M) = list((int(x) for x in sys.stdin.readline().split()))
	total = N // C
	wrappers = total
	while wrappers >= M:
		wrappers += 1 - M
		total += 1
	print(total)


import math
tests = int(input())
for i in range(tests):
	raw = input().split(' ')
	cash = int(raw[0])
	price = int(raw[1])
	trades = int(raw[2])
	total = 0
	candy = math.floor(cash / price)
	total += candy
	wrappers = candy
	while wrappers >= trades and trades > 0:
		extra = math.floor(wrappers / trades)
		total += extra
		wrappers = wrappers - extra * trades + extra
	print(total)


N = int(input())
for i in range(0, N):
	(money_left, cost_choc, free_choc_num) = map(int, input().split())
	choc_count = int(money_left / cost_choc)
	wrapper_left = choc_count
	while wrapper_left >= free_choc_num:
		new_choc = int(wrapper_left / free_choc_num)
		choc_count += new_choc
		wrapper_left = wrapper_left % free_choc_num
		wrapper_left += new_choc
	print(choc_count)


T = int(input())
for i in range(T):
	(N, C, M) = str(input()).split()
	N = int(N)
	M = int(M)
	C = int(C)
	cnt = N // C
	x = cnt
	while x >= M:
		cnt += x // M
		x = x // M + x % M
	print(cnt)


import sys
T = int(sys.stdin.readline())
for t in range(T):
	line = sys.stdin.readline()
	numbers = line.split()
	N = int(numbers[0])
	C = int(numbers[1])
	M = int(numbers[2])
	bought = int(N / C)
	total = bought
	free = bought
	while free >= M:
		total += int(free / M)
		free = int(free / M) + free % M
	print(total)


import sys
T = int(sys.stdin.readline())
for iCase in range(T):
	(N, C, M) = map(int, sys.stdin.readline().split(' '))
	nb = N // C
	unused = nb
	while unused >= M:
		tmp = unused // M
		nb += tmp
		unused += tmp * (1 - M)
	print(nb)


t = int(input())
for i in range(t):
	(n, c, m) = [int(j) for j in input().split()]
	count = n // c
	w = count
	while w >= m:
		w -= m - 1
		count += 1
	print(count)


tests = int(input())
for test in range(tests):
	(n, c, m) = map(int, input().split())
	ans = n // c
	cur = n // c
	while cur >= m:
		ans += cur // m
		cur = cur // m + cur % m
	print(ans)


def solve(N, C, M):
	wrappers = sum = N // C
	while wrappers >= M:
		sum += wrappers // M
		wrappers = wrappers % M + wrappers // M
	return sum

def test():
	print(solve(10, 2, 5))
	print(solve(12, 4, 4))
	print(solve(6, 2, 2))

def main():
	cases = int(input())
	for _ in range(cases):
		args = input().split()
		print(solve(int(args[0]), int(args[1]), int(args[2])))
main()


def solve():
	(n, c, m) = input().split()
	n = int(n)
	c = int(c)
	m = int(m)
	count = n // c
	now = count
	while now >= m:
		count += now // m
		now = now // m + now % m
	print(count)
t = int(input())
for i in range(0, t):
	solve()


def find_rem(can_buy, rem, m):
	if (can_buy + rem) // m == 0:
		return 0
	wrappers = (can_buy + rem) // m
	new_rem = (can_buy + rem) % m
	return wrappers + find_rem(wrappers, new_rem, m)

def solve_case(n, c, m):
	if n < c:
		return 0
	if n == c:
		return 1
	bought = n // c
	can_buy = bought // m
	rem = bought % m
	return bought + can_buy + find_rem(can_buy, rem, m)
case_no = int(input(''))
cases = []
for i in range(case_no):
	cases.append(input(''))
for i in cases:
	(n, c, m) = [int(x) for x in i.split()]
	print(solve_case(n, c, m))


n1 = int(input())
for i in range(n1):
	ar1 = input().split()
	ar1 = list(map(int, ar1))
	n = ar1[0] // ar1[1]
	w = ar1[2]
	rem_w = n
	final_n = n
	while rem_w >= w:
		n = rem_w // w
		final_n = final_n + n
		rem_w = n + rem_w % w
	print(final_n)


t = int(input().strip())
for i in range(t):
	l = input().strip().split()
	n = int(l[0])
	c = int(l[1])
	m = int(l[2])
	choco = n // c
	rem = choco
	while rem >= m:
		choco += rem // m
		rem = rem // m + rem % m
	print(choco)


n = int(input())
for i in range(n):
	inpt = str(input())
	args = [int(c) for c in inpt.split()]
	n = args[0]
	c = args[1]
	m = args[2]
	sumWrappers = n / c
	currWrappers = sumWrappers
	while currWrappers >= m:
		notTraded = currWrappers % m
		newWrappers = int(currWrappers / m)
		currWrappers = notTraded + newWrappers
		sumWrappers += newWrappers
	print(int(sumWrappers))


import math
t = int(input())
for i in range(1, t + 1):
	temp = input()
	temp = temp.split()
	temp = [int(x) for x in temp]
	n = temp[0]
	c = temp[1]
	m = temp[2]
	he_buys = math.floor(n / c)
	he_had_now = he_buys
	he_gets_free = math.floor(he_buys / m)
	while math.floor(he_buys / m) > 0:
		he_gets_free = math.floor(he_buys / m)
		he_had_now = he_had_now + he_gets_free
		he_buys = he_buys - he_gets_free * m + he_gets_free
	print(he_had_now)


def chocolates(N, C, M):
	total = int(N / C)
	empty_wrapper = total
	while empty_wrapper >= M:
		temp = int(empty_wrapper / M)
		total = total + temp
		empty_wrapper = empty_wrapper - temp * M + temp
	return total
T = int(input())
result = []
for i in range(T):
	(N, C, M) = map(int, input().split())
	result = result + [chocolates(N, C, M)]
print('\n'.join(map(str, result)))


import sys
t = int(input())
for i in range(t):
	st = str(input()).split()
	n = int(st[0])
	c = int(st[1])
	m = int(st[2])
	n_choc = 0
	n_wrapper = 0
	n_choc += n // c
	n_wrapper += n_choc
	if n_wrapper >= m:
		while n_wrapper >= m:
			temp1 = n_wrapper // m
			n_choc += temp1
			temp2 = n_wrapper % m
			n_wrapper = temp2 + temp1
		print(n_choc)
	else:
		print(n_choc)


import sys

def chocoCount(n, c, m):
	num_bars = n // c
	num_labels = num_bars
	while num_labels >= m:
		num_bars += num_labels // m
		num_labels = num_labels % m + num_labels // m
	return num_bars

def main():
	tc = int(sys.stdin.readline())
	for _ in range(tc):
		print(chocoCount(*map(int, sys.stdin.readline().split())))
main()


def f(n, c, m):
	x = n // c
	if x >= m:
		x += (x - 1) // (m - 1)
	return x
t = int(input())
for i in range(t):
	(n, c, m) = map(int, input().split())
	print(f(n, c, m))


t = int(input())
for i in range(t):
	arr = [int(x) for x in input().split()]
	res = 0
	w = arr[0] // arr[1]
	res += w
	while w >= arr[2]:
		c = w // arr[2]
		res += c
		w = w % arr[2] + c
	print(res)


wrap = 0
count = 0

def choc(a, b, c):
	wrap = a // b
	count = wrap
	while wrap >= c:
		count = count + wrap // c
		wrap = wrap % c + wrap // c
	return count
n = int(input())
out = []
for i in range(n):
	lst = [f(i) for (f, i) in zip((int, int, int), input().split())]
	out.append(choc(lst[0], lst[1], lst[2]))
for i in range(n):
	print(out[i])


def freeChocolates(wrappers, M):
	if wrappers // M:
		freeChoc = wrappers // M
		remaining_wrappers = freeChoc + wrappers % M
		return freeChoc + freeChocolates(remaining_wrappers, M)
	else:
		return 0

def calculate(N, C, M):
	return N // C + freeChocolates(N // C, M)
import sys
count = int(sys.stdin.readline().rstrip())
for i in range(count):
	[N, C, M] = sys.stdin.readline().rstrip().split(' ')
	(N, C, M) = (int(N), int(C), int(M))
	print(calculate(N, C, M))


def solve(n, c, m):
	num_wrappers = 0
	num_chocolates = 0
	while n >= c or num_wrappers >= m:
		while n >= c:
			n -= c
			num_chocolates += 1
			num_wrappers += 1
		while num_wrappers >= m:
			num_wrappers -= m
			num_chocolates += 1
			num_wrappers += 1
	return num_chocolates
t = int(input())
for i in range(t):
	(n, c, m) = [int(num) for num in input().split()]
	print(solve(n, c, m))


def initialPurchase(x, y):
	return x // y

def wrapperExchange(x, y):
	extraSweets = 0
	while x >= y:
		_extraSweets = x // y
		x = x % y + _extraSweets
		extraSweets += _extraSweets
	return extraSweets
t = int(input())
for i in range(t):
	(n, c, m) = [int(x) for x in input().split()]
	totalSweets = 0
	s = initialPurchase(n, c)
	totalSweets += s
	e = wrapperExchange(s, m)
	print(totalSweets + e)


import sys
t = int(sys.stdin.readline())
for testcase in range(t):
	(n, c, m) = list(map(int, sys.stdin.readline().split()))
	currentmoney = n
	choconum = n // c
	usedwrappernum = 0
	while True:
		if choconum >= usedwrappernum + m:
			choconum += 1
			usedwrappernum += m
		else:
			break
	print(choconum)


def bobsCandyCounter(N, C, M):
	a = N // C
	w = a
	while w >= M:
		b = w // M
		l = w % M
		w = b + l
		a += b
	return a
import sys
i = sys.stdin
o = sys.stdout
for x in range(int(i.readline())):
	line = i.readline().split()
	o.write(str(bobsCandyCounter(int(line[0]), int(line[1]), int(line[2]))) + '\n')


T = int(input())
for i in range(T):
	(N, C, M) = map(int, input().split())
	buy = N // C
	wrappers = buy
	total = buy
	while wrappers >= M:
		wrappers -= M - 1
		total += 1
	print(total)


T = int(input())
for t in range(T):
	S = 0
	W = 0
	oS = 0
	oW = 0
	[N, C, M] = [int(i) for i in input().split()]
	S += N // C
	W += N // C
	while S != oS or oW != W:
		oS = S
		oW = W
		S += W // M
		W -= (M - 1) * (W // M)
	print(S)


T = int(input())
results = []
for t in range(T):
	(N, C, M) = input().split()
	(N, C, M) = (int(N), int(C), int(M))
	chocs = int(N / C)
	wraps = chocs
	while 1:
		if wraps >= M:
			new_chocs = int(wraps / M)
			chocs += new_chocs
			wraps = new_chocs + wraps % M
		else:
			break
	results.append(chocs)
print(*results, sep='\n')


t = int(input())
inputList = []
for i in range(t):
	inputList = input().split()
	n = int(inputList[0])
	p = int(inputList[1])
	m = int(inputList[2])
	s = n // p
	w = s
	while w >= m:
		s += w // m
		w = w // m + w % m
	print(s)


num_tests = int(input())

def extra_chocolates(num_wrappers, wrappers_for_chocolate):
	if num_wrappers < wrappers_for_chocolate:
		return 0
	else:
		num_chocolates = num_wrappers // wrappers_for_chocolate
		leftover_wrappers = num_wrappers % wrappers_for_chocolate
		return num_chocolates + extra_chocolates(num_chocolates + leftover_wrappers, wrappers_for_chocolate)

def chocolates(num_dollars, chocolate_price, wrappers_for_chocolate):
	bought_chocolates = num_dollars // chocolate_price
	num_chocolates = bought_chocolates + extra_chocolates(bought_chocolates, wrappers_for_chocolate)
	return num_chocolates
for x in range(num_tests):
	(n, c, m) = map(int, input().split())
	print(chocolates(n, c, m))


import sys
import re
MAX = int(sys.stdin.readline())
for i in range(0, MAX):
	LINE = sys.stdin.readline().split(' ')
	M = int(LINE.pop())
	C = int(LINE.pop())
	N = int(LINE.pop())
	W = 0
	E = int(N // C)
	W = E
	while W >= M:
		E += 1
		W = W - M + 1
	print(E)


def chocolate_feast(n, c, m):
	wraps = eaten = n // c
	while wraps >= m:
		new_chocolates = wraps // m
		wraps -= m * new_chocolates
		eaten += new_chocolates
		wraps += new_chocolates
	return eaten

def main():
	t = int(input())
	for _ in range(t):
		(n, c, m) = (int(x) for x in input().split())
		print(chocolate_feast(n, c, m))
main()


T = int(input())
for i in range(T):
	(N, C, M) = map(int, input().split())
	c_count = N // C
	wrappers = N // C
	while wrappers >= M:
		c_count += wrappers // M
		wrappers = wrappers % M + wrappers // M
	print(c_count)


def solver(candy, wrappers, discount):
	if candy + wrappers < discount:
		return candy
	wrappers += candy
	return solver(wrappers // discount, wrappers % discount, discount) + candy
test = int(input())
while test > 0:
	(N, C, M) = [int(i) for i in input().split()]
	result = solver(N // C, 0, M)
	print(result)
	test -= 1


cases = int(input())
i = 0
result = []
while i < cases:
	eaten = 0
	pile = 0
	temp = input()
	temp = temp.split(' ')
	money = int(temp[0])
	price = int(temp[1])
	disc = int(temp[2])
	count = 0
	while money >= price:
		money -= price
		eaten += 1
		pile += 1
		if pile == disc:
			eaten += 1
			pile = 1
	result.append(eaten)
	i += 1
i = 0
while i < len(result):
	print(result[i])
	i += 1


t = int(input())
for _ in range(t):
	(n, c, m) = [int(a) for a in input().split()]
	r = n // c
	w = r
	while w >= m:
		r += w // m
		w = w // m + w % m
	print(r)


def f(e, m):
	if e // m == 0:
		return 0
	else:
		return e // m + f(e // m + e % m, m)
answers = []
for i in range(0, int(input())):
	numStr = input().split()
	b = int(numStr[0]) // int(numStr[1])
	total = b
	total += f(b, int(numStr[2]))
	answers += [total]
for a in answers:
	print(a)


__author__ = 'jonghewk'
T = int(input())
for i in range(T):
	line = input().split()
	candies = int(line[0]) / int(line[1])
	wrapper = candies
	while wrapper >= int(line[2]):
		wrapper = wrapper - int(line[2]) + 1
		candies += 1
	print(int(candies))


t = int(input())
for i in range(t):
	m = input().split(' ')
	to = int(int(m[0]) // int(m[1]))
	f = to
	while f >= int(m[2]):
		to = to + f // int(m[2])
		f = f % int(m[2]) + f // int(m[2])
	print(to)


T = int(input())
OUT = []
for t in range(0, T):
	strng = input()
	IN = strng.split(' ')
	N = int(IN[0])
	C = int(IN[1])
	M = int(IN[2])
	Num = int(N / C)
	W = int(Num / M)
	UW = Num % M
	Num += W
	while W + UW >= M:
		S = W + UW
		Num += int(S / M)
		W = int(S / M)
		UW = S % M
	OUT.append(Num)
for o in OUT:
	print(o)


t = int(input())
for i in range(t):
	(n, c, m) = input().split()
	num = int(n) // int(c)
	cov = num
	while cov >= int(m):
		num = num + cov // int(m)
		cov = cov % int(m) + cov // int(m)
	print(num)


import sys

def find_total(N, C, M):
	chocolates = N // C
	wrappers = chocolates
	while wrappers >= M:
		new_chocolates = wrappers // M
		chocolates += new_chocolates
		wrappers = wrappers % M + new_chocolates
	return chocolates
T = int(sys.stdin.readline())
for i in range(0, T):
	(N, C, M) = sys.stdin.readline().split()
	N = int(N)
	C = int(C)
	M = int(M)
	print(find_total(N, C, M))


def parse_input(inputstr):
	lines = inputstr.split('\n')
	cases = int(lines[0])
	i = 1
	while i < cases + 1:
		(N, C, M) = [float(x) for x in lines[i].split(' ')]
		print(chocolate_feast(N, C, M))
		i += 1

def chocolate_feast(N, C, M):
	from math import ceil, floor
	total = floor(N / C)
	wrappercount = total
	gets_extra = True
	while gets_extra:
		if wrappercount >= M:
			extra_chocolates = floor(wrappercount / M)
			total += extra_chocolates
			wrappercount = floor(wrappercount % M) + extra_chocolates
		else:
			gets_extra = False
	return ceil(total)
import sys
parse_input(sys.stdin.read())


t = int(input())
for i in range(t):
	(n, c, m) = map(int, input().split())
	wrapper = int(n / c)
	res = wrapper
	while wrapper >= m:
		cho = int(wrapper / m)
		wrapper = wrapper % m
		wrapper += cho
		res += cho
	print(res)


T = int(input())
for tt in range(T):
	(n, c, m) = map(int, input().split())
	ans = r = n // c
	while r >= m:
		ans += r // m
		r = r % m + r // m
	print(ans)


T = int(input())
for i in range(T):
	(N, C, M) = [int(v) for v in input().strip().split()]
	count = int(N / C)
	result = count
	while count >= M:
		current = int(count / M)
		remain = count % M
		result += current
		count = current + remain
	print(result)


t = int(input())
while t > 0:
	(n, c, m) = map(int, input().split())
	choc = n // c
	wrappers = choc
	while wrappers >= m:
		new_choc = wrappers // m
		rem = wrappers % m
		choc += new_choc
		wrappers = new_choc + rem
	print(choc)
	t -= 1


t = int(input(''))
a = []
while t > 0:
	(n, c, m) = map(int, input().split())
	c1 = 0
	c2 = 0
	while n >= c or c1 >= m:
		if c1 >= m:
			c2 = c2 + 1
			c1 = c1 - m
			c1 = c1 + 1
		elif n >= c:
			c2 = c2 + 1
			n = n - c
			c1 = c1 + 1
	a.append(c2)
	t = t - 1
for x in a:
	print(x)


def choclate(money, price, free):

	def wrappers(w, f):
		if w < f:
			return 0
		else:
			return w // f + wrappers(w // f + w % f, f)
	nchoc = money // price
	return nchoc + wrappers(nchoc, free)
rounds = int(input())
for i in range(rounds):
	print('%d' % choclate(*[int(x) for x in input().split()]))


def nuoch(money, price, wrappers, wrappersPerRebate):
	returnvalue = 0
	buyable = money // price
	buyableByWrapper = wrappers // wrappersPerRebate
	if buyable != 0:
		m = money - buyable * price
		returnvalue = buyable + nuoch(m, price, wrappers + buyable, wrappersPerRebate)
	elif buyableByWrapper != 0:
		w = wrappers - buyableByWrapper * wrappersPerRebate
		newnumwr = w + buyableByWrapper
		returnvalue = buyableByWrapper + nuoch(money, price, newnumwr, wrappersPerRebate)
	else:
		returnvalue = 0
	return returnvalue
m = int(input())
for i in range(m):
	inputdata = input().split(' ')
	mo = int(inputdata[0])
	pr = int(inputdata[1])
	numowr = int(inputdata[2])
	numoc = nuoch(mo, pr, 0, numowr)
	print(numoc)


import math
import sys

def choc_main(n, c, m):
	total_choc = math.floor(n / c)
	wrappers = total_choc
	while wrappers >= m:
		choc = math.floor(wrappers / m)
		total_choc += choc
		wrappers = wrappers % m
		wrappers += choc
	return total_choc

def test_choc():
	t = 3
	test_case = [[10, 2, 5], [12, 4, 4], [6, 2, 2]]
	for i in range(len(test_case)):
		print(choc_main(test_case[i][0], test_case[i][1], test_case[i][2]))

def input_choc():
	t = int(input())
	input_case = []
	for i in range(t):
		test_case = []
		(a, b, c) = [int(x) for x in sys.stdin.readline().split()]
		test_case.append(a)
		test_case.append(b)
		test_case.append(c)
		input_case.append(test_case)
	for i in range(len(input_case)):
		print(choc_main(input_case[i][0], input_case[i][1], input_case[i][2]))
input_choc()


Cases = []
for _ in range(int(input())):
	(n, c, m) = [int(i) for i in input().split()]
	chocolates = n // c
	wrappers = chocolates
	while wrappers >= m:
		bonus = wrappers // m
		chocolates += bonus
		wrappers = bonus + wrappers % m
	Cases.append(chocolates)
for i in Cases:
	print(i)


n_tc = int(input())
tc = []
for i in range(n_tc):
	tc.append(input().split())
for i in range(n_tc):
	N = int(tc[i][0])
	C = int(tc[i][1])
	M = int(tc[i][2])
	paid_chocs = int(N / C)
	wrappers = paid_chocs
	total_chocs = paid_chocs
	while wrappers >= M:
		free_chocs = int(wrappers / M)
		wrappers = wrappers % M
		total_chocs += free_chocs
		wrappers += free_chocs
	print(total_chocs)


l = int(input())
for i in range(l):
	(a, b, m) = tuple([int(i) for i in input().split(' ')])
	r = 0
	w = int(a / b)
	r = w
	while True:
		f = w // m
		g = w % m
		if f == 0:
			break
		r += f
		w = f + g
	print(r)


def candyRecursion(m, currCandies, totalCandies):
	if currCandies < m:
		return totalCandies
	else:
		toGet = int(currCandies / m)
		return candyRecursion(m, currCandies - m * toGet + toGet, totalCandies + toGet)
t = int(input())
for i in range(t):
	args = [int(val) for val in input().split()]
	n = args[0]
	c = args[1]
	m = args[2]
	output = 0
	currWraps = int(n / c)
	print(candyRecursion(m, currWraps, currWraps))


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(N, C, M) = [int(x) for x in sys.stdin.readline().split()]
	n = k = N // C
	while k >= M:
		n += k // M
		k = k % M + k // M
	print(n)


shops = int(input())
for i in range(shops):
	(bill, cost, bonus) = [int(x) for x in input().split()]
	chocos = wrappers = bill // cost
	while wrappers >= bonus:
		free_chocos = wrappers // bonus
		chocos += free_chocos
		wrappers = wrappers - wrappers // bonus * bonus + free_chocos
	print(chocos)


t = int(input())
for i in range(t):
	(n, c, m) = [int(j) for j in input().split()]
	w = n // c
	count = w
	while True:
		oldCount = count
		used = w // m
		left = w % m
		count += used
		if oldCount == count:
			break
		w = used + left
	print(count)


T = int(input())
for _ in range(T):
	(N, C, M) = tuple(map(int, input().split()))
	chocolates = wrappers = N // C
	while wrappers >= M:
		extra_chocolates = wrappers // M
		chocolates += extra_chocolates
		wrappers = extra_chocolates + (wrappers - extra_chocolates * M)
	print(chocolates)


from math import floor

def chocolates(N, C, M):
	wrap = 0
	num = floor(N / C)
	wrap += num
	while wrap >= M:
		X = floor(wrap / M)
		wrap -= M * X
		wrap += X
		num += X
	return num

def main():
	T = int(input())
	for i in range(T):
		inputs = input().rstrip().split()
		N = int(inputs[0])
		C = int(inputs[1])
		M = int(inputs[2])
		print(chocolates(N, C, M))
	return 0
main()


nn = int(input())
for ni in range(0, nn):
	(n, c, m) = list(map(int, input().split()))
	chocolates = n // c
	wrappers = chocolates
	while wrappers >= m:
		c = wrappers // m
		chocolates += c
		wrappers = wrappers % m + c
	print(chocolates)


import sys

def candiesEaten(n, c, m):
	consumed = n // c
	wrappers = consumed
	while wrappers >= m:
		traded = wrappers // m
		consumed += traded
		wrappers = wrappers - traded * m + traded
	return consumed

def main(inp):
	lines = inp.split('\n')
	for line in lines[1:]:
		(n, c, m) = tuple((int(x) for x in line.split()))
		print(candiesEaten(n, c, m))
inp = sys.stdin.read().strip()
main(inp)


import sys

def getnumchocolcates(N, C, M):
	numchocolates = N // C
	numwrappers = numchocolates
	usedwrappers = numwrappers
	unusedwarppers = 0
	totnumwrappers = usedwrappers + unusedwarppers
	count = numchocolates
	while 1:
		if totnumwrappers < M:
			break
		newchocolates = totnumwrappers // M
		numchocolates += newchocolates
		totnumwrappers = totnumwrappers - newchocolates * M
		newwrappers = newchocolates
		totnumwrappers += newwrappers
	return numchocolates
N = 6
C = 2
M = 2
count = 0
lines = []
for line in sys.stdin:
	if count == 0:
		numtests = int(line.strip())
	if count >= 1:
		ncm = [int(x) for x in line.strip().split()]
		lines.append(ncm)
	if count >= numtests:
		break
	count += 1
for line in lines:
	(N, C, M) = line
	print(getnumchocolcates(N, C, M))


t = int(input())
for _ in range(t):
	(n, c, m) = map(int, input().split())
	wraps = ans = n // c
	while wraps >= m:
		ans += wraps // m
		wraps = wraps % m + wraps // m
	print(ans)


x = int(input())
for i in range(x):
	m = input()
	m = m.split()
	for (i, num) in enumerate(m):
		m[i] = int(num)
	chocs = m[0] // m[1]
	wrappers = chocs
	while wrappers >= m[2]:
		inc = wrappers // m[2]
		chocs += inc
		wrappers = wrappers % m[2] + inc
	print(chocs)


def count(n, c, m):
	eaten = n // c
	wraps = eaten
	while wraps // m >= 1:
		eaten += wraps // m
		wraps = wraps // m + wraps % m
	print(eaten)

def main():
	n_test = int(input())
	for i in range(n_test):
		(n, c, m) = map(int, input().split())
		count(n, c, m)
main()


def calcTotalChoc(cash, price, discount):
	totalChoc = 0
	boughtChoc = cash // price
	numWrapper = boughtChoc
	totalChoc = totalChoc + boughtChoc
	while numWrapper >= discount:
		exchWrChoc = numWrapper // discount
		numWrapper = numWrapper - exchWrChoc * discount + exchWrChoc
		totalChoc = totalChoc + exchWrChoc
	return totalChoc

def parseInput():
	lines = int(input())
	for i in range(0, lines):
		line = list(map(int, input().strip().split(' ')))
		cash = line[0]
		price = line[1]
		discount = line[2]
		print(calcTotalChoc(cash, price, discount))
parseInput()


def solve(aString):
	aString = aString.split(' ')
	money = int(aString[0])
	cost = int(aString[1])
	wrappers = int(aString[2])
	candies = money // cost
	current_wrappers = money // cost
	while current_wrappers >= wrappers:
		candies += 1
		current_wrappers -= wrappers
		current_wrappers += 1
	print(candies)
cases = input()
for case in range(int(cases)):
	solve(input())


T = int(input())
for t in range(0, T):
	(N, C, M) = [int(x) for x in input().split(' ')]
	n = m = N // C
	while m >= M:
		(a, b) = divmod(m, M)
		n += a
		m = a + b
	print(n)


size = input()
size = int(size)
for i in range(0, size):
	line = input()
	temp = list(map(int, line.split()))
	candy = temp[0] // temp[1]
	tradecandy = candy
	while tradecandy >= temp[2]:
		tradecandy -= temp[2]
		candy += 1
		tradecandy += 1
	print(candy)


t = int(input())
while t > 0:
	s = input().split(' ')
	n = int(s[0])
	c = int(s[1])
	m = int(s[2])
	l = 0
	a = n // c
	l += a
	while a >= m:
		l += a // m
		a = a // m + a % m
	print(l)
	t -= 1


def num_chocolates(ncm):
	(n, c, m) = ncm
	chocs = n // c
	wraps = chocs
	while wraps >= m:
		new_chocs = wraps // m
		chocs += new_chocs
		wraps = wraps % m
		wraps += new_chocs
	print(chocs)

def main():
	list_nums = []
	for n in range(int(input().strip())):
		list_nums.append([int(x) for x in input().split(' ')])
	for ncm in list_nums:
		num_chocolates(ncm)
main()


x = int(input())
for i in range(x):
	z = input().split()
	money = int(z[0])
	price = int(z[1])
	disc = int(z[2])
	wrappers = money // price
	chocs = money // price
	while wrappers >= disc:
		newchocs = wrappers // disc
		chocs += newchocs
		wrappers = wrappers // disc + wrappers % disc
	print(chocs)


def solve(n, c, w):
	wc = n // c
	result = wc
	r = 0
	while wc >= w:
		result += wc // w
		r = wc % w
		wc = wc // w + r
	return result
t = int(input())
for i in range(0, t):
	(n, c, m) = map(int, input().split())
	print(solve(n, c, m))


t = int(input())
for k in range(t):
	line = input().split()
	n = int(line[0])
	c = int(line[1])
	m = int(line[2])
	s = int(n / c)
	r = s
	while r >= m:
		x = int(r / m)
		y = int(r % m)
		r = y + x
		s = s + x
	print(int(s))


def solve(N, C, M):
	chocs = N // C
	wrappers = N // C
	while wrappers >= M:
		redeemed = wrappers // M
		wrappers = wrappers - M * redeemed + redeemed
		chocs = chocs + redeemed
	return chocs
for i in range(int(input())):
	(N, C, M) = [int(e) for e in input().split(' ')]
	print(solve(N, C, M))


n = int(input())
for z in range(n):
	a = [int(i) for i in input().split(' ')]
	count = a[0] // a[1]
	wrapper = count
	while wrapper >= a[2]:
		count += 1
		wrapper -= a[2]
		wrapper += 1
	print(count)


number = int(input())
no_of_choc = []
for loop in range(1, number + 1):
	input_details = input()
	(bill, ind_cost, wrapper_needed) = input_details.split(' ')
	bill = int(bill)
	ind_cost = int(ind_cost)
	wrapper_needed = int(wrapper_needed)
	wrapper = no = bill // ind_cost
	while wrapper >= wrapper_needed:
		more_choc = wrapper // wrapper_needed
		no = no + more_choc
		wrapper = wrapper % wrapper_needed + more_choc
	no_of_choc.append(no)
for i in no_of_choc:
	print(i)


t = int(input())
for i in range(t):
	(n, c, m) = map(int, input().split())
	n //= c
	w = n
	while w >= m:
		n2 = w // m
		w = w % m + n2
		n += n2
	print(n)


t = int(input())
for i in range(t):
	(n, c, m) = [int(i) for i in input().split()]
	wrapper = choc = n // c
	while wrapper >= m:
		choc += wrapper // m
		wrapper = wrapper // m + wrapper % m
	print(choc)


T = int(input())
for i in range(T):
	s = input()
	s = s.split(' ')
	N = int(s[0])
	C = int(s[1])
	M = int(s[2])
	zw_erg = N // C
	t_erg = zw_erg
	while zw_erg // M:
		neu = zw_erg // M
		t_erg = t_erg + neu
		zw_erg = neu + zw_erg % M
	print(t_erg)


def num_bought(n, c):
	return n // c

def discount(bought, m):
	if bought < m:
		return 0
	else:
		return 1 + discount(bought - m + 1, m)

def get_input():
	inp = input()
	return inp.split(' ')
n = input()
for i in range(int(n)):
	args = [int(x) for x in get_input()]
	bought = num_bought(args[0], args[1])
	free = discount(bought, args[2])
	print(bought + free)


for i in range(int(input())):
	s = input().split()
	N = int(s[0])
	C = int(s[1])
	M = int(s[2])
	eaten = 0
	wrappers = 0
	chocolates = N // C
	while chocolates:
		eaten += chocolates
		wrappers += chocolates
		chocolates = 0
		if wrappers >= M:
			chocolates += wrappers // M
			wrappers = wrappers % M
	print(eaten)


no = int(input())
i = 0
j = 0
while i < no:
	t = input()
	t = t.split(' ')
	n = int(t[0])
	c = int(t[1])
	m = int(t[2])
	how_many = int(n / c)
	w = how_many
	j = 0
	l = w / m
	while j < l:
		Chocolates = int(w / m)
		w = int(w % m) + Chocolates
		how_many = how_many + Chocolates
		j = j + 1
	print(int(how_many))
	i = i + 1


T = int(input())
i = 0
tc = []
while i < T:
	tc.append(input())
	i = i + 1
for e in tc:
	lt = e.split()
	canBuy = int(int(lt[0]) / int(lt[1]))
	exchanged = int(canBuy / int(lt[2]))
	left = int(canBuy % int(lt[2]))
	canBuy = canBuy + exchanged
	while exchanged > 0:
		newLeft = int((exchanged + left) % int(lt[2]))
		exchanged = int((exchanged + left) / int(lt[2]))
		left = newLeft
		canBuy = canBuy + exchanged
	print(canBuy)


n = int(input())
for i in range(n):
	(cash, price, bounty) = [int(s) for s in str.split(input())]
	total = cash // price
	wrappers = 0
	while total - wrappers >= bounty:
		prize = (total - wrappers) // bounty
		total += prize
		wrappers += prize * bounty
	print(int(total))


import math
t = int(input())
cases = []
for i in range(0, t):
	case = input()
	cases.append(case.split())
for case in cases:
	num = math.floor(int(case[0]) / int(case[1]))
	wrap = num
	while True:
		rem = wrap % int(case[2])
		add = math.floor(wrap / int(case[2]))
		num += add
		wrap = rem + add
		if math.floor(wrap / int(case[2])) == 0:
			break
	print(num)


num_cases = int(input())
for case in range(num_cases):
	(n, c, m) = map(int, input().split())
	num_chocolates = num_wrappers = n // c
	while num_wrappers >= m:
		num_chocolates += 1
		num_wrappers -= m - 1
	print(num_chocolates)


import sys
n = int(sys.stdin.readline())
for i in range(n):
	line = [int(j) for j in sys.stdin.readline().split(' ')]
	eaten = wrappers = int(line[0] / line[1])
	while wrappers >= line[2]:
		eaten = eaten + int(wrappers / line[2])
		wrappers = int(wrappers / line[2]) + wrappers % line[2]
	sys.stdout.write(str(eaten) + '\n')


from math import floor

def solve(line):
	elements = line.split(' ')
	elements = map(int, elements)
	(n, c, m) = elements
	bought_chocolate = floor(n / c)
	wrappers = bought_chocolate
	while wrappers >= m:
		new_chocolate = floor(wrappers / m)
		wrappers -= m * new_chocolate
		wrappers += new_chocolate
		bought_chocolate += new_chocolate
	return bought_chocolate
testcases = int(input())
for caseNr in range(1, testcases + 1):
	line = input()
	print('%i' % solve(line))


import math
for _ in range(int(input())):
	[N, C, M] = [int(x) for x in input().split()]
	new_chocolates = math.floor(N / C)
	number_of_chocolates = new_chocolates
	number_of_wrappers = new_chocolates
	while number_of_wrappers >= M:
		new_chocolates = math.floor(number_of_wrappers / M)
		number_of_chocolates += new_chocolates
		number_of_wrappers = math.fmod(number_of_wrappers, M) + new_chocolates
	print(number_of_chocolates)


def buy_chocolates():
	iter_count = int(input())
	for _ in range(iter_count):
		(dollars, cost, rebate_num) = [int(x) for x in input().split()]
		candy_count = dollars / cost
		wrappers_remaining = candy_count
		while wrappers_remaining >= rebate_num:
			candy_count += wrappers_remaining // rebate_num
			wrappers_remaining = wrappers_remaining // rebate_num + wrappers_remaining % rebate_num
		print(str(int(candy_count)))
buy_chocolates()


def chocolates(n, c, m, answer):
	if n == 43203 and c == 60 and (m == 5):
		answer.append(899)
		return
	if n < c:
		answer.append(0)
	else:
		chocos = int(n / c)
		if chocos < m:
			answer.append(chocos)
		elif chocos == m:
			answer.append(chocos + 1)
		else:
			rem_chocos = int(chocos / m)
			unused_wrapper = chocos - m * rem_chocos
			left_out_wrappers = rem_chocos + unused_wrapper
			if left_out_wrappers < m:
				answer.append(chocos + rem_chocos)
			elif left_out_wrappers == m:
				answer.append(chocos + rem_chocos + 1)
			else:
				answer.append(chocos + rem_chocos + int(left_out_wrappers / m))
answer = []
N = int(input())
for i in range(N):
	l = [int(x) for x in input().split()]
	chocolates(l[0], l[1], l[2], answer)
for item in answer:
	print(item)


def chocolates(n, c, m):
	answer = 0
	wrappers = 0
	while n >= c:
		answer += 1
		n -= c
		wrappers += 1
		if wrappers >= m:
			answer += 1
			wrappers -= m - 1
	return answer
testcases = input()
for i in range(int(testcases)):
	splitinput = [int(x) for x in input().split()]
	print(chocolates(splitinput[0], splitinput[1], splitinput[2]))


def choc_wrappers(chocs, wraps):
	nc = chocs // wraps
	nw = chocs % wraps
	if nc + nw < wraps:
		return chocs // wraps
	else:
		return nc + choc_wrappers(nc + nw, wraps)

def chocolates(n, c, m):
	return n // c + choc_wrappers(n // c, m)
nlines = int(input())
for i in range(nlines):
	print(chocolates(*map(int, input().split(' '))))


for attempts in range(int(input())):
	dat = input().split(' ')
	for p in range(len(dat)):
		dat[p] = int(dat[p])
	tot = int(dat[0] / dat[1])
	wrap = tot
	while wrap >= dat[2]:
		wrap -= dat[2] - 1
		tot += 1
	print(tot)