#P10390. [蓝桥杯 2024 省 A] 因数计数

[蓝桥杯 2024 省 A] 因数计数

Problem Description

Xiaolan casually wrote down an array {a1,a2,,an}\{a_1, a_2,\cdots, a_n\} containing nn positive integers. He found that he can easily count how many ordered pairs (i,j)(i, j) satisfy that aja_j is a divisor of aia_i. Therefore, he defines an integer pair (x1,y1)(x_1, y_1) to be a “divisor” of another integer pair (x2,y2)(x_2, y_2) if and only if x1x_1 and y1y_1 are divisors of x2x_2 and y2y_2, respectively. He wants to know how many ordered quadruples (i,j,k,l)(i, j, k, l) satisfy that (ai,aj)(a_i, a_j) is a divisor of (ak,al)(a_k, a_l), where i,j,k,li, j, k, l are all distinct.

Input Format

The first line contains a positive integer nn.
The second line contains nn positive integers a1,a2,,ana_1, a_2,\cdots, a_n, separated by a single space.

Output Format

Output one line containing an integer representing the answer.

5
3 6 2 2 7
4

Hint

Quadruple (1,4,2,3)(1, 4, 2, 3): (3,2)(3, 2) is a divisor of (6,2)(6, 2).
Quadruple (1,3,2,4)(1, 3, 2, 4): (3,2)(3, 2) is a divisor of (6,2)(6, 2).
Quadruple (4,1,3,2)(4, 1, 3, 2): (2,3)(2, 3) is a divisor of (2,6)(2, 6).
Quadruple (3,1,4,2)(3, 1, 4, 2): (2,3)(2, 3) is a divisor of (2,6)(2, 6).

Constraints:
For 20%20\% of the testdata, n50n \le 50.
For 40%40\% of the testdata, n104n \le 10^4.
For all testdata, 1n1051 \le n \le 10^5 and 1ai1051 \le a_i \le 10^5.

Input Format

Output Format

Translated by ChatGPT 5