Each pizza consists of 44 slices. There are 𝑁N friends and each friend needs exactly 𝑋X slices.
Find the minimum number of pizzas they should order to satisfy their appetite.
Input Format
- The first line of input will contain a single integer 𝑇T, denoting the number of test cases.
- Each test case consists of two integers 𝑁N and 𝑋X, the number of friends and the number of slices each friend wants respectively.
Output Format
For each test case, output the minimum number of pizzas required.
Constraints
- 1≤𝑇≤1001≤T≤100
- 1≤𝑁,𝑋≤101≤N,X≤10
Sample 1
Inputcopy | Outputcopy |
---|---|
4 1 5 2 6 4 3 3 5 | 2 3 3 4 |
Test case 11: There is only 11 friend who requires 55 slices. If he orders 11 pizza, he will get only 44 slices. Thus, at least 22 pizzas should be ordered to have required number of slices.
Test case 22: There are 22 friends who require 66 slices each. Thus, total 1212 slices are required. To get 1212 slices, they should order 33 pizzas.
Test case 33: There are 44 friends who require 33 slices each. Thus, total 1212 slices are required. To get 1212 slices, they should order 33 pizzas.
Test case 44: There are 33 friends who require 55 slices each. Thus, total 1515 slices are required. To get 1515 slices, they should order at least 44 pizzas.
Solutions:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
// Function to calculate the minimum number of pizzas required
public static List<Integer> minPizzas(int T, List<int[]> cases) {
List<Integer> results = new ArrayList<>();
for (int[] caseArr : cases) {
int N = caseArr[0];
int X = caseArr[1];
int totalSlices = N * X;
int pizzas = totalSlices / 4;
if (totalSlices % 4 != 0) {
pizzas++;
}
results.add(pizzas);
}
return results;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Number of test cases
int T = scanner.nextInt();
// Test cases
List<int[]> cases = new ArrayList<>();
for (int i = 0; i < T; i++) {
int N = scanner.nextInt();
int X = scanner.nextInt();
cases.add(new int[]{N, X});
}
// Calculate the minimum number of pizzas required
List<Integer> results = minPizzas(T, cases);
// Print the results
for (int result : results) {
System.out.println(result);
}
scanner.close();
}
}