#214EasyMath & Number Theory· Greatest Common Divisor of an Array
Common Gear Pitch
Input format
`teeth`: an array of tooth counts.
Output format
A single integer: the largest positive integer that divides every tooth count.
Examples
Input: teeth = [12, 18, 24]
Output: 6
Link sizes 1, 2, 3 and 6 divide all three counts, and 6 is the largest.
Input: teeth = [7, 13]
Output: 1
The two counts share no divisor except 1, so only the smallest possible link works.
Input: teeth = [48]
Output: 48
With one gear every divisor works, and the largest divisor of 48 is 48 itself.
Constraints
- 1 <= teeth.length <= 10^5
- 1 <= teeth[i] <= 10^9
- #math
- #gcd
- #euclid
- #number-theory