The Birthday Party
InterviewTime limit1sMemory limit128 MB
Find the smallest guest count m so that every candy pile leaves at least one leftover when divided equally among m guests.
- Level
Medium4 of 10
- Topics
- Number theory, Array
- Solved
- No attempts yet
Problem
Little Kasia is throwing a birthday party. For the occasion she bought different kinds of candy; there are candies of the -th kind.
Kasia hands the candy out to the guests she invites. For each kind, every guest must receive the same number of candies, and candies cannot be broken into pieces. When more than one amount per guest is possible, she always picks the largest one. For example, with candies and guests she could give each person , , or candies, so she gives the maximum, each. Thus if there are guests, every guest receives candies of the -th kind and Kasia keeps of them.
Kasia has not tasted any of the candy yet, so she wants at least one candy of every kind to remain for herself after the sharing. In other words, for every the remainder of divided by must be at least . Kasia is not very sociable, so find the smallest number of guests she must invite to satisfy this condition.
Input
The first line contains an integer , the number of candy kinds ().
The second line contains integers , separated by spaces, where is the number of candies of the -th kind ().
Output
Print a single integer: the smallest number of guests Kasia must invite.