Find Minimum Possible Difference of Largest and Smallest of Crackers in C++



Suppose we have two numbers N and K. We want to distribute N crackers to K users. We have to find the minimum possible difference between the largest number of crackers received by a user and smallest number received by a user.

So, if the input is like N = 7; K = 3, then the output will be 1, because when the users receive two, two and three crackers, respectively, the difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.

Steps

To solve this, we will follow these steps −

if n mod k is same as 0, then:
   return 0
Otherwise
   return 1

Example

Let us see the following implementation to get better understanding −

Open Compiler
#include <bits/stdc++.h> using namespace std; int solve(int n, int k){ if (n % k == 0){ return 0; } else{ return 1; } } int main(){ int N = 7; int K = 3; cout << solve(N, K) << endl; }

Input

7, 3

Output

1
Updated on: 2022-03-03T07:13:47+05:30

300 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements