PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000228. Đếm dãy con có ƯCLN bằng một (Coprime Subsequences)
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 dãy con có ƯCLN bằng một (Coprime Subsequences)
Coprime Subsequences
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers , count non-empty subsequences whose GCD is . Subsequences are distinguished by selected indices, even if their values are equal. Print the count modulo .
Input
First line contains ; second line contains .
Output
Print the count modulo .
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Example 1
Input
3
1 2 3
Output
5
Explanation
The five valid subsequences by indices are (1), (1,2), (1,3), (2,3), and (1,2,3).
Example 2
Input
4
1 1 1 1
Output
15
Explanation
Every non-empty subsequence has GCD 1, so the answer is .