#abc230g. G - GCD Permutation

G - GCD Permutation

Score : 600600 points

问题描述

给定一个从 11NN 的整数排列 P=(P1,P2,,PN)P=(P_1,P_2,\ldots,P_N)

找出满足以下条件的整数对 (i,j)(i,j) 的数量:1ijN1\leq i\leq j\leq N,且 GCD(i,j)1\text{GCD}(i,j)\neq 1 以及 GCD(Pi,Pj)1\text{GCD}(P_i,P_j)\neq 1

这里,对于正整数 xxyyGCD(x,y)\text{GCD}(x,y) 表示 xxyy 的最大公约数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Given is a permutation P=(P1,P2,,PN)P=(P_1,P_2,\ldots,P_N) of the integers from 11 through NN.

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

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • (P1,P2,,PN)(P_1,P_2,\ldots,P_N) is a permutation of (1,2,,N)(1,2,\ldots,N).
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

P1P_1 P2P_2 \ldots PNP_N

Output

Print the answer.

Sample Input 1

6
5 1 3 2 4 6

Sample Output 1

6

Six pairs (3,3)(3,3), (3,6)(3,6), (4,4)(4,4), (4,6)(4,6), (5,5)(5,5), (6,6)(6,6) satisfy the condition, so 66 should be printed.

Sample Input 2

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

Sample Output 2

32

update @ 2024/3/10 10:04:00

}