PROBLEM LINK:
Author: Shubham Jain
Tester: Shubham Jain
Editorialist: Shubham Jain
DIFFICULTY:
Easy
PREREQUISITES:
Basic Programming, Maths
PROBLEM:
You’re organizing fresher’s party today. You’re expecting ‘n’ freshers and you’ve already arranged ‘m’ beer cans. You want to distribute all the beers among your juniors in such a way that each fresher receives the same number of beer cans. Note you cannot divide a beer can into halves. Find the minimum number of additional beer cans you must buy so that each fresher receives same number of beer cans.
EXPLANATION:
There are n freshers and m beer cans. Then each fresher will get m/n number of beer cans.
Now this fraction needs to be a whole number so we calculate the ceiling of m/n i.e. ceil(m/n).
Total number of beer cans expected for n freshers will be ceil(m/n) x n.
Subtracting the m beer cans which is already given, we get (ceil(m/n) x n) – m.
AUTHOR’s SOLUTION:
#include "iostream"
#include "cmath"
using namespace std;
int main(void){
int t;
cin >> t;
while(t--){
double n, m;
cin >> n >> m;
cout << (int)(ceil(m/n)*n - m) << endl;
}
return 0;
}