Question-6:

Totaram loves Mithai. He frequently goes to his favorite (Tauji ka store), Tauji, to buy them. They are having a promotion at Tauji. If Totaram saves enough wrappers, he can turn them in for a free chocolate.

For example, Toataram has n=10 to spend on bars of Mithai that cost c=2 each. He can turn in m=5 wrappers to receive another bar. Initially, he buys 5 bars and has 5 wrappers after eating them. He turns in 5 of them, leaving him with 0 ,for 1 more bars. After eating that one, he only has 0 wrapper, and his feast ends. Overall, he has eaten 5+1=6 bars.

  • n: an integer representing Totaram's initial amount of money
  • c: an integer representing the cost of a mithai bar
  • m: an integer representing the number of wrappers he can turn in for a free bar.

Sample Input

3
10    2    5
12    4     4
6       2      2

Sample Output:

6

3

5

Solution:

import math
import os
import random
import re
import sys

# Complete the chocolateFeast function.
def chocolateFeast(n, c, m):
    kl=[]
    wl=[]
    k=n//c
    kl.append(k)
    q=100000
    while(q!=0):
        s=0
        q=math.floor(k/m)
        kl.append(q)
        wl.append(q)
        r=k%m
        wl.append(r)
        for i in wl:
            s=s+i
        k=s
        wl.clear()
    
    s1=0
    for j in kl:
        s1=s1+j
    return s1

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'],
            'w')

    t = int(input())

    for t_itr in range(t):
        ncm = input().split()

        n = int(ncm[0])

        c = int(ncm[1])

        m = int(ncm[2])

        result = chocolateFeast(n, c, m)

        fptr.write(str(result) + '\n')

    fptr.close()