PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000255. Tổng Ước Chung Lớn Nhất của Các Bộ Số (Sum of gcd of Tuples (Hard))

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 NN and KK. Consider all ordered sequences A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) of length exactly NN with 1≤Ai≤K1\le A_i\le K for every position ii.

Two sequences are different if they differ in at least one position. Equal elements are allowed. Since each position has KK possible values, there are exactly KNK^N such sequences.

For each sequence, define g(A)=gcd⁡(A1,A2,…,AN)g(A)=\gcd(A_1,A_2,\ldots,A_N), the greatest common divisor of all its entries. Find the sum of g(A)g(A) over every valid sequence.

Because the sum may be extremely large, output it modulo 109+710^9+7.

Input

  • One line containing two space-separated integers NN and KK.
  • NN is the number of elements in each sequence, and KK is the maximum allowed value of any element.

Output

Print one integer: the sum of gcd⁡(A1,A2,…,AN)\gcd(A_1,A_2,\ldots,A_N) over all valid sequences, modulo 109+710^9+7.

Subtasks

  • Subtask 1 (15 points): 2≤N≤62\le N\le6; 1≤K≤61\le K\le6.
  • Subtask 2 (20 points): 2≤N≤1002\le N\le100; 1≤K≤2001\le K\le200.
  • Subtask 3 (25 points): 2≤N≤1052\le N\le10^5; 1≤K≤1041\le K\le10^4.
  • Subtask 4 (40 points): 2≤N≤1052\le N\le10^5; 1≤K≤1051\le K\le10^5.

Examples

Example 1

Input

3 2

Output

9

Explanation

Each sequence contains three entries, each either 11 or 22, so there are 23=82^3=8 sequences. Seven sequences, (1,1,1)(1,1,1), (1,1,2)(1,1,2), (1,2,1)(1,2,1), (1,2,2)(1,2,2), (2,1,1)(2,1,1), (2,1,2)(2,1,2) and (2,2,1)(2,2,1), have gcd equal to 11. The remaining sequence (2,2,2)(2,2,2) has gcd equal to 22. The answer is 7⋅1+2=97\cdot1+2=9.

Example 2

Input

3 200

Output

10813692

Explanation

There are 2003=8 000 000200^3=8\,000\,000 ordered sequences of three values in [1,200][1,200]. For every dd between 11 and 200200, precisely ⌊200/d⌋3\lfloor200/d\rfloor^3 sequences have every entry divisible by dd.

Using the identity x=∑d∣xφ(d)x=\sum_{d\mid x}\varphi(d), the total can be evaluated by summing the contributions φ(d)⌊200/d⌋3\varphi(d)\lfloor200/d\rfloor^3. For example, the contributions for d=1,2,3,4d=1,2,3,4 are respectively 8 000 0008\,000\,000, 1 000 0001\,000\,000, 574 992574\,992, and 250 000250\,000. The sum over all 200200 choices of dd is 10 813 69210\,813\,692, so the required output is 10813692.

Example 3

Input

100000 100000

Output

742202979

Explanation

Every sequence has 100 000100\,000 elements and each element has 100 000100\,000 possible values. There are 100000100000100000^{100000} valid sequences, which makes individual enumeration impractical. The sum of their gcd values modulo 109+710^9+7 equals 742202979. Both input parameters attain their maximum allowed values.