Maze movement
Time limit2sMemory limit256 MB
Find the max people per minute from the lowest to the highest room where pairs sharing a divisor above 1 are linked with capacity equal to their gcd.
- Level
Medium7 of 10
- Topics
- Graph, Number theory
- Solved
- No attempts yet
Problem
Your boss gave you the task of designing a walk-through maze, and you are comparing several layouts. Before you settle on one, you want to know how quickly people can move in and out of each layout. Your boss wants this venture to make money, and the faster people move through, the more paying customers you can handle.
A maze is a set of numbered rooms and the passages connecting them. The only entrance is the lowest-numbered room and the only exit is the highest-numbered room.
Each passage limits how many people can pass through at a time. For rooms numbered and , a passage joins them whenever the greatest common divisor of and is larger than . Call that divisor . Then people per minute can walk from to , and at the same time people per minute can walk from to . The entrance, the exit, and every room handle any number of people at a time. People want to get through the maze as quickly as possible, so they never wait in a room.
Input
The input describes a single maze. The first line holds the number of rooms . ()
Each of the next lines holds one room number. The room numbers are distinct, and each one is between and .
Output
Print the largest number of people per minute that can enter the maze, assuming people leave the maze at the same rate they enter it. No maze given in the input supports more than people entering per minute.