-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSolution.java
31 lines (27 loc) · 853 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package Practice.Algorithms.Implementation.ChocolateFeast;
import java.util.Scanner;
public class Solution {
private static int chocolateFeast(int n, int c, int m) {
int wrappers = 0;
int sum = (int) Math.floor(n / c);
wrappers += sum;
while (wrappers >= m) {
int trade = (int) Math.floor(wrappers / m);
wrappers -= (trade * m) - trade;
sum += trade;
}
return sum;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int a0 = 0; a0 < t; a0++) {
int n = in.nextInt();
int c = in.nextInt();
int m = in.nextInt();
int result = chocolateFeast(n, c, m);
System.out.println(result);
}
in.close();
}
}