AtCoder Beginner Contest 230
G
GCD Permutation
AtCoder
⌀ 2516
原题
←H →
翻译中…

Problem Statement

翻译中…

Given is a permutation $P=(P_1,P_2,\ldots,P_N)$ of the integers from $1$ through $N$.

翻译中…

Find the number of pairs of integers $(i,j)$ such that $1\leq i\leq j\leq N$ satisfying $GCD(i,j)\neq 1$ and $GCD(P_i,P_j)\neq 1$. Here, for positive integers $x$ and $y$, $GCD(x,y)$ denotes the greatest common divisor of $x$ and $y$.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 2\times 10^5$
  • $(P_1,P_2,\ldots,P_N)$ is a permutation of $(1,2,\ldots,N)$.
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
P_1 P_2 \ldots P_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
6
5 1 3 2 4 6
Output #1
6
Six pairs $(3,3)$, $(3,6)$, $(4,4)$, $(4,6)$, $(5,5)$, $(6,6)$ satisfy the condition, so $6$ should be printed.
Input #2
12
1 2 3 4 5 6 7 8 9 10 11 12
Output #2
32
题目信息
题号
abc230_g
时间限制
5 s
内存限制
1024 MB

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