GCD Of Differences

GCD Of Differences

Hard Computer Mathematics GCD/LCM & Euclid 32 views
Explanation Complexity

Problem Statement

Given n numbers, print gcd of all |ai-a1|.

Input Format

n then n integers.

Output Format

One integer.

Example

4
6 10 14 18
4

Constraints

n>=2

Input / Output Format

Input Format
n then n integers.
Output Format
One integer.
Constraints
n>=2

Examples

Input:
4 6 10 14 18
Output:
4

Example Solution (Public)

Computer Mathematics
Compute base=a1. For i>=2 take d=abs(ai-base), g=gcd(g,d). Output g.

Official Solution Code

Compute base=a1. For i>=2 take d=abs(ai-base), g=gcd(g,d). Output g.
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.