#P1408. 互质数列sequence【数据疑似有误】

互质数列sequence【数据疑似有误】

Description

A sequence has nn numbers. We define an operation: we can divide two adjacent numbers simultaneously by one of their common divisors, and the cost of this operation is the value of that divisor. After performing such operations several times, we can transform the original sequence so that every pair of adjacent numbers is coprime. Find the minimum total cost to achieve this.

Input Format

The first line contains a positive integer nn. In the next nn lines, each line contains an integer, representing each number in the sequence in order.

Output Format

Output the minimum cost.

3
3
12
6

5

Hint

  • 30% of the testdata satisfies n20n \leq 20.
  • 100% of the testdata satisfies 1n100001 \leq n \leq 10000, and the numbers in the sequence satisfy 1Ai2×1071 \leq A_i \leq 2 \times 10^7.

Translated by ChatGPT 5