#SP0000226. Đưa các số về bằng nhau (Equalize)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đư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 positive integers. Make all array elements equal using as few operations as possible. One operation chooses exactly one index and performs one of the following:
- Multiply by any prime number .
- Divide by a prime divisor of , 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 . The second line contains positive integers .
Output
Print the minimum number of prime multiplication or division operations to make all values equal.
Subtasks
-
Subtask 1 (20 points): ; for every .
-
Subtask 2 (30 points): ; for every .
-
Subtask 3 (50 points): ; for every .
Examples
Input
3
4 9 6
Output
4
Explanation
The array is . Choose the common target . Transform (divide by , then multiply by ) in moves. Transform in moves; the value needs none. Total: moves. This is minimal because the exponent vectors of primes and are and ; for each prime, changing the three exponents to their median requires at least moves. The total lower bound is achieved.