Codeforces Round 846 (Div. 2)
F
Three Chairs
Codeforces
2300
原题
← EG →
翻译中…

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.

翻译中…

Note

翻译中…

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

翻译中…

样例

Input #1
3
1 2 3
Output #1
1
InputCopy OutputCopy
Input #2
4
1 6 2 3
Output #2
3
InputCopy OutputCopy
Input #3
4
16 4 8 2
Output #3
0
InputCopy OutputCopy
Input #4
10
10 1 6 7 9 8 4 3 5 2
Output #4
77
InputCopy OutputCopy
题目信息
题号
1780F
时间限制
1 s
内存限制
256 MB
标签
位运算
暴力
组合数学
数据结构
动态规划
数论
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。