Sort by

recency

|

1265 Discussions

|

  • + 0 comments

    Here is my easy c++ solution , you can watch the explanation here : https://youtu.be/RZti_qPbiAA

    int chocolateFeast(int n, int c, int m) {
        int result = 0, wrappers = 0;
        while( n >= c){
            result ++;
            wrappers ++;
            n -= c;
            if(wrappers == m){
                result ++;
                wrappers = 1;
            }
        }
        return result;
    }
    
  • + 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();
        }
    }
    
  • + 0 comments
    def chocolateFeast(n, c, m):
        tot=n//c
        wr=tot
        while wr>=m:
            ch=wr//m
            tot+=ch
            r=wr%m
            wr=r+ch
        return tot
    
  • + 0 comments

    This problem is a geometric series so can be solved with maths.

    int chocolateFeast(int n, int c, int m) {
        return ((long)(n/c)*m-1)/(m-1);
    }
    
  • + 0 comments
    def chocolateFeast(n, c, m):
        a=o=n//c
        for _ in range(5):
          if a<m:
            break
          o+=(a//m)
          a=(a//m)+(a%m)
        return o