HWKGB - EDITORIAL

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();
    }

I Think Editorialist’s Solution is wrong.
use else if instead of second if.
My Code:
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define mod 1000000007
using namespace std;
int main()
{
lli t;
cin>>t;
while(t–)
{
lli x,b; cin>>x>>b;
if(x>=b && x%b==0)
cout<<0<<endl;
else if(x<b)
cout<<b-x<<endl;
else
{
lli q=x/b;
q++;
lli sum=q*b;
cout<<sum-x<<endl;
}
}
}

The editorial has a function solve() and calls return in each block. Hence didn’t required else if.
If you are writing directly in main, you will need that else if