PROBLEM LINK:
HWKGB
Author: h4wk
Editorialist: shreyashlrn1
DIFFICULTY:
EASY
PREREQUISITES:
Math
PROBLEM:
Smallest number need to make a number divisible by another number
EXPLANATION:
Simple mathematics is required. If X is already divisible by B answer is 0, else find the
minimum divisible number greater than X.
SOLUTIONS:
Setter's Solution
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
unsigned long long int a, b;
cin>>a>>b;
if(a < b)
{
cout<<b - a<<endl;
continue;
}
if(a % b == 0)
{
cout<<0<<endl;
continue;
}
else
{
cout<<(b - (a % b))<<endl;
}
}
return 0;
}
Editorialist's Solution
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int x,b; cin>>x>>b;
if(x>=b && x%b==0)
{
cout<<0; return;
}
if(x<b)
{
cout<<b-x; return;
}
else
{
int q=x/b;
q++;
int sum=q*b;
cout<<sum-x; return;
}
}
int32_t main()
{
solve();
}