Algorithm


Problem Name: beecrowd | 2896

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2896

Enjoy the Offer

 

By Paulo E. D. Pinto, UERJ- Universidade do Estado do Rio de Janeiro BR Brazil

Timelimit: 1

A supermarket is doing a sales promotion for soft drinks. If one day you buy soft drinks and bring the empty bottles the next day, they exchange each set of K empty bottles for a full one. A customer wants to make the most of this offer and therefore bought 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 use it to the fullest.

Make a program to calculate this.

 

Input

 

The first input line contains integer T (1 ≤ T ≤ 10000), which indicates the number of test cases. In each of the following T lines come two integers N and K (1 ≤ K, N ≤ 10000), respectively the number of soft drinks bought and the number of empty bottles to gain a full.

 

Output

 

For each test case print the number of bottles that the customer will have on the second day, if he makes the most of the offer.

 

 

 

Input Sample Output Sample

3
7 4
4 7
4000 7

4
4
574

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
int main(void){
    int n, i;
    int x, y;

    scanf("%d", &n);

    while (n--)
    {

        scanf("%d %d", &x, &y);

        int contador = 0;
        for (i = x; i >= y; i -= y)
            ++contador;

        printf("%d\n", contador + i);

    }
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
3 7 4 4 7 4000 7

Output

x
+
cmd
4 574

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int t, a, b, x;
    cin >> t;
    vector<int>v(t);
    for (int i = 0; i  <  t; ++i)
    {
        cin >> a >> b;
        x=a/b;
        x+=a%b;
        cout << x << endl;
    }
    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
3 7 4 4 7 4000 7

Output

x
+
cmd
4 574

#3 Code Example with Java Programming

Code - Java Programming


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
         Scanner leitor = new Scanner(System.in);
        int T = leitor.nextInt();
        for (int i = 0; i  <  T; i++) {
        	int N = leitor.nextInt();
        	int K = leitor.nextInt();
        	System.out.println((N % K) + (N / K));
        }
    }
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
3 7 4 4 7 4000 7

Output

x
+
cmd
4 574

#4 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("fs")
const [[numLines], ...lines] = readFileSync("/dev/stdin", "utf8")
	.split("\n")
	.map((line) => line.split(" ").map(value => Number.parseInt(value, 10)))


function main() {
	const responses = []

	for (let i = 0; i  <  numLines; i++) {
		const [purchasedNum, emptiesNum] = lines[i]
		const bottlesLeftsOnHands = Math.trunc(purchasedNum / emptiesNum) + (purchasedNum) % (emptiesNum)

		responses.push(bottlesLeftsOnHands)
	}

	console.log(responses.join("\n"))
}

main()
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 7 4 4 7 4000 7

Output

x
+
cmd
4 574

#5 Code Example with Python Programming

Code - Python Programming

start coding...
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 7 4 4 7 4000 7

Output

x
+
cmd
4 574
Advertisements

Demonstration


Previous
#2879 Beecrowd Online Judge Solution 2879 Desvendando Monty Hall Solution in C, C++, Java, Js and Python
Next
#2930 Beecrowd Online Judge Solution 2930 Final Thesis of Christmas Depression Solution in C, C++, Java, Js and Python