#B2071. Find the Minimal Divisor with Equal Remainders

    ID: 11153 Type: Default 1000ms 256MiB

Find the Minimal Divisor with Equal Remainders

Find the Minimal Divisor with Equal Remainders

Given three positive integers \(a\), \(b\), and \(c\), and an integer \(x\) such that \(x > 1\), when \(a\), \(b\), and \(c\) are divided by \(x\), they all yield the same remainder. It is guaranteed that there exists a valid \(x\) satisfying this condition. Your task is to determine the smallest such \(x\) (i.e. the minimal \(x > 1\) ) that satisfies \(a \bmod x = b \bmod x = c \bmod x\).

Hint:

This condition is equivalent to requiring that \(x\) divides the differences \(|a - b|\), \(|b - c|\) and \(|a - c|\). Therefore, if \(d = \operatorname{gcd}(|a-b|, |b-c|, |a-c|)\), then the required \(x\) is the minimal divisor of \(d\) that is greater than \(1\). In the special case where \(a = b = c\), any \(x > 1\) works so the answer is \(2\).

inputFormat

The input consists of a single line containing three positive integers \(a\), \(b\), and \(c\) separated by spaces.

outputFormat

Output a single integer which is the smallest \(x > 1\) that satisfies the condition.

sample

5 15 10
5