Are They All Integers?
InterviewTime limit2sMemory limit1024 MB
Decide whether (A[i]-A[j])/A[k] is an integer for every choice of three distinct indices in a sorted list.
- Level
Easy3 of 10
- Topics
- Brute force, Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
Computing with integers alone is a dream for every programmer. There is no need to deal with floating point numbers, estimated errors, and the like. We do not even need floating point units in our computers for divisions!
Your company claims it has a brand new computational model that solves integer problems efficiently. As a software engineer at the Integer Computing Processors Company (ICPC), you are going to write a validator that checks the following.
Given a list of positive integers A[0], ..., A[n − 1]. Suppose you pick three different elements of this list arbitrarily, A[i], A[j], A[k], with i, j, k being mutually different. Is it true that (A[i]−A[j])/A[k] is always an integer?
Input
The first line of the input contains one integer n indicating the number of positive integers in the list. The second line of the input contains n positive integers A[0], ..., A[n − 1] separated by blanks.
Output
If (A[i]−A[j])/A[k] is always an integer, output yes. Otherwise output no.
Constraints
- 3 ≤ n ≤ 50
- 1 ≤ A[0] ≤ A[1] ≤ ... ≤ A[n − 1] ≤ 100