• + 0 comments

    JavaCode

    import java.io.*;
    import java.util.*;
    
    class Result {
        public static int chocolateFeast(int n, int c, int m) {
            int totalBars = n / c;
            int totalWrappers = totalBars;
            while (totalWrappers >= m) {
                int newBars=totalWrappers / m; 
                totalBars +=newBars; 
                totalWrappers= totalWrappers% m+newBars; 
            }
            return totalBars;
        }
    }
    
    public class trys {
        public static void main(String[] args) throws IOException {
            Scanner s = new Scanner(System.in);
            int testCaseCount = s.nextInt();
            for (int i = 0; i < testCaseCount; i++) {
                int n = s.nextInt(); 
                int c = s.nextInt(); 
                int m = s.nextInt(); 
                System.out.println(Result.chocolateFeast(n, c, m));
            }
            s.close();
        }
    }