Last Updated: 27 Aug, 2025

Minimal Divisibility Pair

Easy

Problem statement

You are given two positive integers, 'a' and 'b'.

Your task is to find the smallest possible sum of x + y, where x and y are non-negative integers that you can add to 'a' and 'b' respectively, such that the resulting number (b + y) is perfectly divisible by the resulting number (a + x).


Input Format:
The first line of input contains two space-separated integers, 'a' and 'b'.


Output Format:
Print a single integer representing the minimum possible value of x + y.


Note:
x and y must be greater than or equal to 0.
The condition to satisfy is (b + y) % (a + x) == 0.