#GL0000255. Tổng Ước Chung Lớn Nhất của Các Bộ Số (Sum of gcd of Tuples (Hard))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng Ước Chung Lớn Nhất của Các Bộ Số (Sum of gcd of Tuples (Hard))
Sum of gcd of Tuples (Hard)
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given two positive integers and . Consider all ordered sequences of length exactly with for every position .
Two sequences are different if they differ in at least one position. Equal elements are allowed. Since each position has possible values, there are exactly such sequences.
For each sequence, define , the greatest common divisor of all its entries. Find the sum of over every valid sequence.
Because the sum may be extremely large, output it modulo .
Input
- One line containing two space-separated integers and .
- is the number of elements in each sequence, and is the maximum allowed value of any element.
Output
Print one integer: the sum of over all valid sequences, modulo .
Subtasks
- Subtask 1 (15 points): ; .
- Subtask 2 (20 points): ; .
- Subtask 3 (25 points): ; .
- Subtask 4 (40 points): ; .
Examples
Example 1
Input
3 2
Output
9
Explanation
Each sequence contains three entries, each either or , so there are sequences. Seven sequences, , , , , , and , have gcd equal to . The remaining sequence has gcd equal to . The answer is .
Example 2
Input
3 200
Output
10813692
Explanation
There are ordered sequences of three values in . For every between and , precisely sequences have every entry divisible by .
Using the identity , the total can be evaluated by summing the contributions . For example, the contributions for are respectively , , , and . The sum over all choices of is , so the required output is 10813692.
Example 3
Input
100000 100000
Output
742202979
Explanation
Every sequence has elements and each element has possible values. There are valid sequences, which makes individual enumeration impractical. The sum of their gcd values modulo equals 742202979. Both input parameters attain their maximum allowed values.