Daisies and Love
InterviewTime limit1sMemory limit1024 MB
Find the largest M so that every petal count L_i is congruent to some common value modulo M, where all L_i are multiples of M.
- Level
Medium4 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
An M-state affection list (with ) is a sequence defined as follows: the first entry is the state “loves”, and the remaining entries are some other (distinct) affection states.
A girl reads a boy's feelings toward her by plucking, one at a time, the petals of a daisy he gives her, using the following rules:
- Before the first petal is plucked, we are in the state “loves”.
- Each time a petal is plucked, the affection state advances to the next state in the list.
- The state that follows the last state in the list is again “loves” (the list wraps around).
- When the flower has no petals left, we finish with this daisy and return the current state as its result.
For example, consider the -state list “loves”-“likes”-“indifferent”. With this list, a daisy of petals gives the result “indifferent”, while a daisy of petals gives “likes”.
The girl believes the boy loves her only if he gives her daisies and every one of them points to the state “loves”. The boy wants to convince her, so he gives her daisies and wants to design the longest possible affection list.
For the given daisies, find the largest value of for which the girl concludes that the boy loves her.
Input
The first line contains the number of daisies (). The second line contains integers () separated by spaces, where is the number of petals on the -th daisy.
Output
Print a single integer: the largest possible value of . If the petal counts of the daisies share no common divisor greater than , print .