#P10390. Divisor Pair Quadruplets

    ID: 12398 Type: Default 1000ms 256MiB

Divisor Pair Quadruplets

Divisor Pair Quadruplets

You are given an array of n positive integers \(\{a_1, a_2, \ldots, a_n\}\). A pair \((x_1, y_1)\) is said to be a divisor pair of \((x_2, y_2)\) if and only if \(x_1\) divides \(x_2\) and \(y_1\) divides \(y_2\) (i.e. \(x_1\mid x_2\) and \(y_1\mid y_2\)).

Your task is to count the number of ordered quadruplets \((i, j, k, l)\) such that:

  • The indices \(i, j, k, l\) are all distinct.
  • \(a_i\mid a_k\) and \(a_j\mid a_l\), meaning that the pair \((a_i, a_j)\) is a divisor pair of \((a_k, a_l)\).

All formulas are in \(\LaTeX\) format. Solve the problem and output the number of quadruplets satisfying the conditions.

inputFormat

The first line of input contains a single integer \(n\) -- the number of elements in the array.

The second line contains \(n\) space-separated positive integers \(a_1, a_2, \ldots, a_n\).

outputFormat

Output a single integer representing the number of ordered quadruplets \((i, j, k, l)\) that satisfy the condition that \(a_i\mid a_k\) and \(a_j\mid a_l\) with all indices distinct.

sample

4
1 2 3 4
2