atcoder#AGC020B. [AGC020B] Ice Rink Game
[AGC020B] Ice Rink Game
Score : points
Problem Statement
An adult game master and children are playing a game on an ice rink. The game consists of rounds. In the -th round, the game master announces:
- Form groups consisting of children each!
Then the children who are still in the game form as many groups of children as possible. One child may belong to at most one group. Those who are left without a group leave the game. The others proceed to the next round. Note that it's possible that nobody leaves the game in some round.
In the end, after the -th round, there are exactly two children left, and they are declared the winners.
You have heard the values of , , ..., . You don't know , but you want to estimate it.
Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of exist.
Constraints
- All input values are integers.
Input
Input is given from Standard Input in the following format:
Output
Print two integers representing the smallest and the largest possible value of , respectively, or a single integer if the described situation is impossible.
4
3 4 3 2
6 8
For example, if the game starts with children, then it proceeds as follows:
- In the first round, children form groups of children, and nobody leaves the game.
- In the second round, children form group of children, and children leave the game.
- In the third round, children form group of children, and child leaves the game.
- In the fourth round, children form group of children, and child leaves the game.
The last children are declared the winners.
5
3 4 100 3 2
-1
This situation is impossible. In particular, if the game starts with less than children, everyone leaves after the third round.
10
2 2 2 2 2 2 2 2 2 2
2 3