Same Remainder Divisors
InterviewTime limit1sMemory limit128 MB
Given N distinct integers, find all M greater than 1 for which all numbers share the same remainder mod M, output divisors of pairwise differences in increasing order.
- Level
Medium4 of 10
- Topics
- Number theory, Math, Brute force
- Solved
- No attempts yet
Problem
You are given N distinct positive integers. Find every integer M greater than 1 such that all of the given numbers leave the same remainder when divided by M.
Input
The first line contains N, the number of integers written down. (2 <= N <= 100)
Each of the next N lines contains one integer. Every integer is at least 1 and at most 1,000,000,000, and no integer appears more than once.
The input is always chosen so that at least one valid M exists.
Output
Print all possible values of M on one line, separated by spaces. The values must be printed in increasing order.