Infinite Stakes
At the heart of the Mathematical Mirage Casino, Parsa finds himself at the Color Roulette table—a game known to bankrupt geniuses and thrill mathematicians.
Laid out before him is an infinite roulette strip, each integer position on the -axis representing a pocket to be painted. The dealer deals Parsa
enchanted chips, each representing a unique magical color with a mystical constraint.
Each chip has a locking interval
. When Parsa drops chip
on pocket
, he's bound by roulette law to to color every multiple of
away from
with the same chip—pockets at
,
and so on, forever.
The house rule is firm: every pocket must receive exactly one color, and the periodicity of each chip must be strictly respected. Parsa can smell the jackpot… but first, he must count.
In how many distinct ways can he paint the entire roulette line under these constraints?
The pit boss assures him the answer is finite, but Parsa must compute it modulo to make it out with his winnings.
Will he walk away a legend?
Input
The first line of input contains
, the number of distinct chip colors.
The second line contains integers, where the
th number represents
,
the periodicity of each chip color
.
Output
Print how many distinct valid ways there are to assign colors to all the pockets on the -axis, using the given chips and obeying their periodic constraints.
Clarifications
- You can imagine we have infinitely many chips of each color available.
- You can use a color any number of times (including zero).
Examples
Input 1
3
1 1 1
Output 1
3
Explanation
Since all of our colors have a periodicity of
, we can only use one of them to color the whole thing. So since we have
colors to do so, there are
different valid ways.
Input 2
2
2 4
Output 2
4
Explanation
Let's say the colour with is blue, and the other one is red. There are four possible ways to colour the entire roulette strip:
- Colour every point blue.
- Colour every point red.
- Colour the even-numbered points blue and the odd-numbered ones red.
- Colour the odd-numbered points blue and the even-numbered ones red.
Input 3
4
1 2 4 4
Output 3
26
Comments