PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000231. Sức mạnh của các nhóm chiến binh (Winter is here)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Sức mạnh của các nhóm chiến binh (Winter is here)
Sức mạnh của các nhóm chiến binh (Winter is here)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
For each nonempty subsequence of the given array whose GCD exceeds , assign the score (subsequence length) times (its GCD). Return the sum of these scores modulo . Positions are distinct.
Input
- First line: integer .
- Second line: array elements.
Output
Print the weighted sum modulo .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
3
3 3 1
Output
12
Explanation
The only qualifying groups are the two singletons with value 3 and their two-element group; their weighted sum is .
Example 2
Input
4
2 3 4 6
Output
39
Explanation
Summing the weights of all subsequences with GCD greater than one gives 39.