Preparando MOJI

Three Chairs

1000ms 262144K

Description:

One day Kira found $$$n$$$ friends from Morioh and decided to gather them around a table to have a peaceful conversation. The height of friend $$$i$$$ is equal to $$$a_i$$$. It so happened that the height of each of the friends is unique.

Unfortunately, there were only $$$3$$$ chairs in Kira's house, and obviously, it will not be possible to seat all friends! So, Kira has to invite only $$$3$$$ of his friends.

But everything is not so simple! If the heights of the lowest and the tallest of the invited friends are not coprime, then the friends will play tricks on each other, which will greatly anger Kira.

Kira became interested, how many ways are there to choose $$$3$$$ of his friends so that they don't play tricks? Two ways are considered different if there is a friend invited in one way, but not in the other.

Formally, if Kira invites friends $$$i$$$, $$$j$$$, and $$$k$$$, then the following should be true: $$$\gcd(\min(a_i, a_j, a_k), \max(a_i, a_j, a_k)) = 1$$$, where $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of the numbers $$$x$$$ and $$$y$$$.

Kira is not very strong in computer science, so he asks you to count the number of ways to invide friends.

Input:

The first line contains the number $$$n$$$ ($$$3 \le n \le 3\cdot10^5$$$) — the number of Kira's friends.

The next line contains $$$n$$$ distinct integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 3\cdot10^5$$$) — heights of Kira's friends.

Output:

In a single line output the number of ways to invite three friends.

Sample Input:

3
1 2 3

Sample Output:

1

Sample Input:

4
1 6 2 3

Sample Output:

3

Sample Input:

4
16 4 8 2

Sample Output:

0

Sample Input:

10
10 1 6 7 9 8 4 3 5 2

Sample Output:

77

Note:

In the first example, only one way is suitable: invite friends $$$1$$$, $$$2$$$, and $$$3$$$. Here $$$1 < 2 < 3$$$, and the numbers $$$1$$$ and $$$3$$$ are coprime.

Informação

Codeforces

Provedor Codeforces

Código CF1780F

Tags

bitmasksbrute forcecombinatoricsdata structuresdpnumber theorysortings

Submetido 0

BOUA! 0

Taxa de BOUA's 0%

Datas 09/05/2023 10:36:05

Relacionados

Nada ainda