Given an array of $n$ positive integers $a_1, a_2, \ldots, a_n$. You can perform the following operation any number of times:
- Increase or decrease any element $a_i$ by 1, as long as the element remains a positive integer ($a_i \ge 1$).
Find the minimum number of operations required such that the product of all elements in the array becomes a power of a prime number.
That is, $\prod_{i=1}^n a_i = p^k$, where $p$ is a prime number and $k$ is a non-negative integer.
#### Input
- The first line contains an integer $n$ ($1 \leq n \leq 10^5$).
- The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^7$).
#### Output
- Output a single integer, the minimum number of operations required.
#### Subtasks
- **Subtask 1 (10%):** $n = 1$.
- **Subtask 2 (20%):** $n \le 5$ and $a_i \le 20$.
- **Subtask 3 (30%):** $n \le 1000$ and $a_i \le 1000$.
- **Subtask 4 (20%):** $a_i \le 3$.
- **Subtask 5 (10%):** $a_i \le 10^5$.
- **Subtask 6 (10%):** $a_i \le 10^7$.
#### Example
Input:
```
3
3 5 8
```
Output:
```
2
```
Explanation:
We can change the array to $[2, 4, 8]$ (product $64 = 2^6$).
- Change $3 \to 2$ (1 op)
- Change $5 \to 4$ (1 op)
- $8$ remains $8$ (0 ops)
Total operations: 2.
Target prime $p=2$.