#C737. Smallest Common Modulus
Smallest Common Modulus
Smallest Common Modulus
Given an array of integers, your task is to find the smallest positive integer \( k \) such that for every element \( a_i \) in the array, the remainder when \( a_i \) is divided by \( k \) is the same. Formally, for an array \( [a_1, a_2, \dots, a_n] \) (with \( n \ge 2 \)), you need to determine \( k = \gcd(|a_2 - a_1|, |a_3 - a_2|, \dots, |a_n - a_{n-1}|) \).
Special cases:
- If the array is empty, output
None
. - If the array contains only one element, output that element.
- If all elements of the array are identical, the result should be
0
because every consecutive difference is 0.
This problem tests your understanding of the greatest common divisor (GCD) and modular arithmetic. Use efficient approaches to handle edge cases and large inputs.
inputFormat
The input is given via standard input (stdin). The first line contains an integer \( n \) representing the number of elements in the array. The second line contains \( n \) space-separated integers.
outputFormat
Output the smallest positive integer \( k \) that satisfies the condition. If the array is empty, output None
. If the array has only one element, output that element.
0
None