#GL0000271. Tổng bội chung nhỏ nhất của các cặp (LCMs)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng bội chung nhỏ nhất của các cặp (LCMs)
LCMs
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of positive integers . For every pair of different positions such that , consider the least common multiple .
Compute the sum of these least common multiples over all position pairs. Even if two positions contain equal values, their pair must still be counted exactly once. Print the answer modulo .
Input
- The first line contains an integer , the length of the sequence.
- The second line contains exactly integers in sequence order.
Output
Print one integer, $\displaystyle\sum_{1\le i<j\le N}\operatorname{lcm}(A_i,A_j)$ modulo .
Subtasks
- Subtask 1 (20 points): ; for each .
- Subtask 2 (30 points): ; for each .
- Subtask 3 (50 points): ; for each .
Examples
Example 1
Input
3
2 4 6
Output
22
Explanation
There are three pairs: the LCMs of , , and are , , and , respectively. Thus the answer is .
Example 2
Input
8
1 2 3 4 6 8 12 12
Output
313
Explanation
The eight positions give distinct pairs. The values at positions 7 and 8 still form a valid pair with LCM . Grouping the contributions by the first position gives the following sums:
- Position 1 (value ): .
- Position 2 (value ): .
- Position 3 (value ): .
- Position 4 (value ): .
- Position 5 (value ): .
- Position 6 (value ): .
- Position 7 (value ): .
Their total is .
Example 3
Input
10
356822 296174 484500 710640 518322 888250 259161 609120 592348 713644
Output
353891724
Explanation
There are pairs of positions. Evaluate each pair using and sum all contributions modulo . This gives . Use a sufficiently wide integer type or modular arithmetic to avoid overflow.