Sep-05-2023, 02:48 PM
(This post was last modified: Sep-05-2023, 02:48 PM by ramonrocha.)
CHALLENGE
A supermarket is doing a sale promotion of soft drinks. If one day you buy soda and take the empty hulls the next day, she exchanges each set of K empty bottles for a full bottle. A customer wants to make the most of this offer and buys several bottles on the first day of the promotion. Now, he wants to know how many bottles he will have at the end of the second day of the promotion if he uses it to the maximum.
INPUT
The first input line contains integer T (1 <=T <=10000), which indicates the number of test cases. On each of the following T lines come two integers N and K (1 <=K, N <= 10000), respectively the number of soft drinks purchased and the number of empty bottles to win a full.
OUTPUT
For each test case, print the number of bottles the customer will have on the second day if they make the most of the offer.
TEST - INPUT
3
7 4
4 7
4000 7
TEST - OUTPUT
4
4
574
---
START OF THE CODE
T = int(input())
for i in range(T):
---
Your Output:
9
4
4666
A supermarket is doing a sale promotion of soft drinks. If one day you buy soda and take the empty hulls the next day, she exchanges each set of K empty bottles for a full bottle. A customer wants to make the most of this offer and buys several bottles on the first day of the promotion. Now, he wants to know how many bottles he will have at the end of the second day of the promotion if he uses it to the maximum.
INPUT
The first input line contains integer T (1 <=T <=10000), which indicates the number of test cases. On each of the following T lines come two integers N and K (1 <=K, N <= 10000), respectively the number of soft drinks purchased and the number of empty bottles to win a full.
OUTPUT
For each test case, print the number of bottles the customer will have on the second day if they make the most of the offer.
TEST - INPUT
3
7 4
4 7
4000 7
TEST - OUTPUT
4
4
574
---
START OF THE CODE
T = int(input())
for i in range(T):
---
def soda_promotion(n, k): bottles = n # Initially, we have N purchased bottles empty_bottles = n # Start with all bottles being empty while empty_bottles >= k: # Exchange K empty bottles for one full bottle exchanged_bottles = empty_bottles // k bottles += exchanged_bottles # Add the exchanged bottles to the total empty_bottles = exchanged_bottles + (empty_bottles % k) # Update the number of empty bottles return bottles T = int(input()) for i in range(T): n, k = map(int, input().split()) bottles = soda_promotion(n, k) print(bottles)The code above is not giving the expected result:
Your Output:
9
4
4666