Minimum and maximum number of N chocolates after distribution among K students Last Updated : 18 Jun, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given N Chocolates and K students, the task is to find how to divide the chocolates such that the difference between the minimum and maximum chocolate received by all students is minimized. Print the value of minimum and maximum chocolate distribution.Examples: Input: N = 7, K = 3 Output: Min = 2, Max = 3 Distribution is 2 2 3 Input: N = 100, K = 10 Output: 10 10 Distribution is 10 10 10 10 10 10 10 10 10 10 Approach: The difference will only be minimized when each student gets an equal number of candies that is N % k = 0 but if N % K != 0 then each student will 1st get (N-N%k)/k amount of candy then the rest N%k amount of candies can be distributed to N%K students by giving them each 1 candy. Thus there will be just 1 more candy than the (N-N%k)/k if N % K != 0 with a student.Below is the implementation of the above approach: CPP // CPP implementation of the above approach #include <bits/stdc++.h> using namespace std; // Driver code int main(){ int n = 7, k = 3; if(n % k == 0) cout<<n/k<<" "<<n/k; else cout<<((n-(n % k))/k)<<" " <<(((n-(n % k))/k) + 1); return 0; } // This code is contributed by Sanjit_Prasad Java // Java implementation of the above approach public class Improve { // Driver code public static void main(String args[]) { int n = 7 ; int k = 3 ; if (n % k == 0) System.out.println(n / k +" " + n / k); else System.out.println((n-(n % k)) / k + " " + (((n-(n % k))/ k) + 1) ) ; } // This Code is contributed by ANKITRAI1 } Python # Python implementation of the above approach n, k = 7, 3 if(n % k == 0): print(n//k, n//k) else: print((n-n % k)//k, (n-n % k)//k + 1) C# // C# implementation of the // above approach using System; class GFG { // Driver code public static void Main() { int n = 7 ; int k = 3 ; if (n % k == 0) Console.WriteLine(n / k + " " + n / k); else Console.WriteLine((n - (n % k)) / k + " " + (((n - (n % k)) / k) + 1)); } } // This code is contributed // by inder_verama PHP <?php // PHP implementation of the above approach // Driver code $n = 7; $k = 3; if($n % $k == 0) echo $n/$k . " " . $n/$k; else echo (($n - ($n % $k)) / $k) . " " . ((($n - ($n % $k)) / $k) + 1); // This code is contributed // by Akanksha Rai(Abby_akku) ?> JavaScript <script> // JavaScript implementation of the above approach // Driver code var n = 7 ; var k = 3 ; if (n % k == 0) document.write(n / k +" " + n / k); else document.write((n-(n % k)) / k + " " + (((n-(n % k))/ k) + 1) ) ; // This code is contributed by 29AjayKumar </script> Output: 2 3 Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Maximum number of chocolates to be distributed equally among k students I indrajit1 Follow Improve Article Tags : DSA school-programming Similar Reads Maximum number of chocolates to be distributed equally among k students Given n boxes containing some chocolates arranged in a row. There are k number of students. The problem is to distribute maximum number of chocolates equally among k students by selecting a consecutive sequence of boxes from the given lot. Consider the boxes are arranged in a row with numbers from 1 9 min read Number of chocolates left after k iterations Given a pile of chocolates and an integer 'k' i.e. the number of iterations, the task is to find the number of chocolates left after k iterations. Note: In every iteration, we can choose a pile with a maximum number of chocolates, after that square root of chocolate remains and rest is eaten. Exampl 4 min read Maximum and Minimum apples distribution limits Given an integer N representing a number of apples and an array weights[] consisting weight of these apples. Distribute them to K people such that they receive equal-weighing apples. Each person must receive at least one apple. Cutting an apple in half is restricted, the task is to print the maximum 11 min read Minimum number of mails required to distribute all the questions Given N questions in a test and K students in the class. Out of the batch of K students, N students memorised exactly one question each. A mail can contain about a maximum of X questions. Find the minimum number of mails required so that the entire class gets to know about all the questions. NOTE: A 6 min read Minimum number of mails required to distribute all the questions Given N questions in a test and K students in the class. Out of the batch of K students, N students memorised exactly one question each. A mail can contain about a maximum of X questions. Find the minimum number of mails required so that the entire class gets to know about all the questions. NOTE: A 6 min read Distributed C candies among N boys such that difference between maximum and minimum candies received is K Given two integers N and C, representing the number of boys and candies, and an integer K, the task is to calculate the maximum and the minimum number of candies received by any boy such that the difference between them is K. Examples: Input: N = 4, C = 12, K = 3Output:Maximum = 5Minimum = 2Explanat 7 min read Like