PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000226. Đưa các số về bằng nhau (Equalize)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đưa các số về bằng nhau (Equalize)

Equalize

Source: CodeChef

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of nn positive integers. Make all array elements equal using as few operations as possible. One operation chooses exactly one index ii and performs one of the following:

  • Multiply aia_i by any prime number pp.
  • Divide aia_i by a prime divisor pp of aia_i, if such a divisor exists.

Intermediate values need not stay within the initial input bounds. The final common positive integer can be chosen freely. Find the minimum number of operations.

Input

The first line contains integer nn. The second line contains nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print the minimum number of prime multiplication or division operations to make all values equal.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le15; 1≤ai≤1051\le a_i\le10^5 for every ii.

  • Subtask 2 (30 points): 1≤n≤20001\le n\le2000; 1≤ai≤1051\le a_i\le10^5 for every ii.

  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤ai≤1051\le a_i\le10^5 for every ii.

Examples

Input

3
4 9 6

Output

4

Explanation

The array is (4,9,6)(4,9,6). Choose the common target 6=2⋅36=2\cdot3. Transform 4→2→64\to2\to6 (divide by 22, then multiply by 33) in 22 moves. Transform 9→3→69\to3\to6 in 22 moves; the value 66 needs none. Total: 44 moves. This is minimal because the exponent vectors of primes 22 and 33 are (2,0,1)(2,0,1) and (0,2,1)(0,2,1); for each prime, changing the three exponents to their median 11 requires at least 22 moves. The total lower bound 2+2=42+2=4 is achieved.