#P5856. 「SWTR-3」Game

    ID: 4754 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp数学O2优化状态压缩,状压

「SWTR-3」Game

Description

Little E has nn positive integers a1,a2,,ana_1,a_2,\dots,a_n. He can perform the following operation any number of times:

Choose a number qq and a set S={d1,d2,,dm}S=\{d_1,d_2,\dots,d_m\} such that ad1,ad2,,adma_{d_1},a_{d_2},\dots,a_{d_m} are divisible by qq, and divide ad1,ad2,,adma_{d_1},a_{d_2},\dots,a_{d_m} by qq.

  • qq must be in the form pzp^z, where pp is a prime number and zz is a positive integer.

Find the minimum number of operations needed to make all these numbers equal.

Input Format

The first line contains an integer nn.

The second line contains nn integers a1,a2,,ana_1,a_2,\dots,a_n.

Output Format

Output one integer representing the answer.

5
12 30 48 36 18

4
10
72 81 27 90 45 45 27 99 45 18

6
4
1 2 4 8
2

Hint

"Sample 1 Explanation"

The initial sequence is 12 30 48 36 18.
Choose S={4,5},p=3S=\{4,5\},p=3, after the operation it becomes 12 30 48 12 6.
Choose S={1,3,4},p=2S=\{1,3,4\},p=2, after the operation it becomes 6 30 24 6 6.
Choose S={2},p=5S=\{2\},p=5, after the operation it becomes 6 6 24 6 6.
Choose S={3},p=22=4S=\{3\},p=2^2=4, after the operation it becomes 6 6 6 6 6.
A total of 4 operations are used, and the method is not unique.

"Constraints and Notes"

This problem uses bundled testdata.

Subtask ID nn\leq aia_i\leq Special Property Score
11 88 5050 There is a number equal to 11 among aia_i 1313
22 1010 100100 None 1717
33 10310^3 10410^4 2929
44 10510^5 10610^6 4141

For 100%100\% of the data, 1n1051\leq n\leq 10^5 and 1ai1061\leq a_i\leq 10^6.

For all test points, the time limit is 1s and the memory limit is 128MB.

"Source"

Sweet Round 03 B
idea & solution: ET2006 & Alex_Wei。

Translated by ChatGPT 5