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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đế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 , count index pairs with . Different indices count separately even if values are repeated. The count may exceed 32-bit integer limits.
Input
First line contains ; second line has .
Output
Print the number of valid pairs.
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
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.