This page is still under construction.

Parts of this page are still being built. What you see may change.

Maze movement

Time limit2sMemory limit256 MB

Summary
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 xx and yy, a passage joins them whenever the greatest common divisor of xx and yy is larger than 11. Call that divisor pp. Then pp people per minute can walk from xx to yy, and at the same time pp people per minute can walk from yy to xx. 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 nn. (2≤n≤10002 \le n \le 1000)

Each of the next nn lines holds one room number. The room numbers are distinct, and each one is between 22 and 2×1092 \times 10^9.

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 10910^9 people entering per minute.

Examples2

  1. Example 1

    Input
    4
    4
    6
    8
    9
    
    Expected output
    3
    
  2. Example 2

    Input
    7
    25289
    17017
    2601
    325
    225
    55223
    190969
    
    Expected output
    18