PROBLEM 20
Easy

Next Multiple Distance

Programming Basics · C++

</>
STATUS Not solved

TASK

Problem

#20

In “Next Multiple Distance”, input integer data and given n and positive k, print how much must be added to n to reach a multiple of k.

EXAMPLE

Example

Input
10 3
Output
2

LIMITS

Constraints

0 ≤ values ≤ 10^12; every divisor/capacity is positive.
📖
LEARN Theory for this problem
+

For non-negative integers, `/` gives the integer quotient and `%` gives the remainder.

Connection to “Next Multiple Distance”: here, intermediate values are best kept in named variables so the formula stays readable and data types remain clear.

💡
NEED HELP? Hints
+

['Choose division and remainder operations that match the requested decomposition.', 'After solving “Next Multiple Distance”, verify the algorithm on your own small example and on an allowed boundary case. Print only the required result with no extra text.']

ANSWER Solution
+
#include <iostream>
using namespace std;
int main() {
    long long n, k;
    cin >> n >> k;
    cout << (k - n % k) % k << '\n';
    return 0;
}