PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000241. Tổng độ tốt của mọi dãy con (GCD Goodness)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng độ tốt của mọi dãy con (GCD Goodness)
Tổng độ tốt của mọi dãy con (GCD Goodness)
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
For every nonempty subsequence selected by indices, define its goodness as (GCD of chosen elements) times (sum of chosen elements). Calculate the total goodness of all nonempty subsequences modulo .
Input
- First line: integer .
- Second line: array elements.
Output
Print the total goodness modulo .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
4
2 4 6 9
Output
350
Explanation
Summing the goodness of all 15 nonempty subsequences gives 350.
Example 2
Input
1
5
Output
25
Explanation
The only nonempty subsequence is , with goodness .