PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000229. Đếm cặp phần tử nguyên tố cùng nhau (Counting Coprime Pairs)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm cặp phần tử nguyên tố cùng nhau (Counting Coprime Pairs)

Counting Coprime Pairs

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given positive integers a1,…,ana_1,\ldots,a_n, count index pairs 1≤i<j≤n1\le i<j\le n with gcd⁡(ai,aj)=1\gcd(a_i,a_j)=1. Different indices count separately even if values are repeated. The count may exceed 32-bit integer limits.

Input

First line contains nn; second line has aia_i.

Output

Print the number of valid pairs.

Subtasks

  • Subtask 1 (20 points): 2≤n≤100, 1≤ai≤1002\le n\le 100,\ 1\le a_i\le 100.

  • Subtask 2 (30 points): 2≤n≤10000, 1≤ai≤100002\le n\le 10000,\ 1\le a_i\le 10000.

  • Subtask 3 (50 points): 2≤n≤100000, 1≤ai≤10000002\le n\le 100000,\ 1\le a_i\le 1000000.

Examples

Example 1

Input

8
5 4 20 1 16 17 5 15

Output

19

Explanation

Counting all index pairs with GCD 1 gives 19. In particular, the element 1 is coprime to every other element.

Example 2

Input

3
2 4 6

Output

0

Explanation

Every pair has a common divisor 2, so no pair is coprime.