MeetCode
GCD Of Differences
C
C++
Computer Mathematics
CSS
DSA
HTML
Java
JavaScript
NodeJS
PHP
Programming Interview
Python
ReactJS
SQL
Run
Submit
Dark
Problem Statement
Solutions
Submissions
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
Input
4 6 10 14 18
Output
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
Wrap
Copy
Compute base=a1. For i>=2 take d=abs(ai-base), g=gcd(g,d). Output g.
Please
login
to submit solutions.
Editor
C
C++
Computer Mathematics
CSS
DSA
HTML
Java
JavaScript
NodeJS
PHP
Programming Interview
Python
ReactJS
SQL
Test Cases
Output
Submission Result
Input
4 6 10 14 18
Expected Output
4
Compile Output
Error
Output
Please
login
to submit solutions.