Problems > Coprime Pairs

Coprime Pairs

Difficulty: 2100 6000 ms 128 MB

number-theory mobius

Count the index pairs i < j with gcd(ai, aj) = 1.

Input: the first line has N; the second line has N positive integers.

Output: the number of coprime pairs.

Constraints:

  • 2 ≤ N ≤ 105
  • 1 ≤ ai ≤ 105

Sample Tests

Input 1
3
2 3 4
Output 1
2
Input 2
2
6 6
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.