Square
Time limit1sMemory limit1024 MB
Given a sequence a, choose positive integers t so that each adjacent pair a_i t_i a_{i+1} t_{i+1} is a perfect square, minimizing the product of all t_i modulo 1000000007.
- Level
Medium7 of 10
- Topics
- Number theory, Greedy, Graph
- Solved
- No attempts yet
Problem
Father Study loves math very much.
Given a sequence of integers , Father Study wants to calculate another sequence of integers that satisfies the following conditions.
- For each , .
- For each , is a square number. (In mathematics, a square number or perfect square is an integer that is the square of an integer, in other words, it is the product of some integer with itself.)
- is minimized.
Find the minimum value of .
Input
The first line contains a single integer ().
The second line contains integers () separated by single spaces.
Output
Output one integer, the minimum value of modulo .