102306: [AtCoder]ABC230 G - GCD Permutation

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

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.


Sample Input 1

6
5 1 3 2 4 6

Sample 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.


Sample Input 2

12
1 2 3 4 5 6 7 8 9 10 11 12

Sample Output 2

32

Input

题意翻译

给你一个长度为 $N$ 的排列 $P=(P_1,P_2,...,P_N)$,你需要求出有多少 $(i,j)$ 满足 $1\leq i \leq j \leq N,\gcd(i,j)\ne 1,\gcd(P_i,P_j)\ne 1$。

Output

分数:600分

问题描述

给定一个整数$1$到$N$的排列$P=(P_1,P_2,\ldots,P_N)$。

找出满足$1\leq i\leq j\leq N$且$GCD(i,j)\neq 1$和$GCD(P_i,P_j)\neq 1$的整数对$(i,j)$的数量。

其中,对于正整数$x$和$y$,$GCD(x,y)$表示$x$和$y$的最大公约数。

约束

  • $1 \leq N \leq 2\times 10^5$
  • $(P_1,P_2,\ldots,P_N)$是$(1,2,\ldots,N)$的一个排列。
  • 输入中的所有值都是整数。

输入

从标准输入以如下格式获取输入:

$N$
$P_1$ $P_2$ $\ldots$ $P_N$

输出

打印答案。


样例输入1

6
5 1 3 2 4 6

样例输出1

6

有六对$(3,3)$, $(3,6)$, $(4,4)$, $(4,6)$, $(5,5)$, $(6,6)$满足条件,因此应打印$6$。


样例输入2

12
1 2 3 4 5 6 7 8 9 10 11 12

样例输出2

32

加入题单

算法标签: