E - Sum of gcd of Tuples (Hard) Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500500

問題文

11 以上 KK 以下の整数からなる長さ NN の数列 {A1,...,AN}\{A_1,...,A_N\} を考えます。

そのようなものは KNK^N 個ありますが、その全てについての gcd(A1,...,AN)\gcd(A_1,...,A_N) の和を求めてください。

ただし、答えは非常に大きくなる可能性があるため、和を (109+7)(10^9+7) で割ったあまりを出力してください。

なお、gcd(A1,...,AN)\gcd(A_1,...,A_N)A1,...,ANA_1,...,A_N の最大公約数を表します。

制約

  • 2N1052 \leq N \leq 10^5
  • 1K1051 \leq K \leq 10^5
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

NN KK

出力

KNK^N 個の数列全てについての gcd(A1,...,AN)\gcd(A_1,...,A_N) の和を (109+7)(10^9+7) で割ったあまりを出力せよ。


入力例 1Copy

Copy
3 2

出力例 1Copy

Copy
9

gcd(1,1,1)+gcd(1,1,2)+gcd(1,2,1)+gcd(1,2,2)\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2) +gcd(2,1,1)+gcd(2,1,2)+gcd(2,2,1)+gcd(2,2,2)+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2) =1+1+1+1+1+1+1+2=9=1+1+1+1+1+1+1+2=9

となるため、答えは 99 です。


入力例 2Copy

Copy
3 200

出力例 2Copy

Copy
10813692

入力例 3Copy

Copy
100000 100000

出力例 3Copy

Copy
742202979

和を 109+710^9+7 で割った余りを出力してください。

Score : 500500 points

Problem Statement

Consider sequences {A1,...,AN}\{A_1,...,A_N\} of length NN consisting of integers between 11 and KK (inclusive).

There are KNK^N such sequences. Find the sum of gcd(A1,...,AN)\gcd(A_1, ..., A_N) over all of them.

Since this sum can be enormous, print the value modulo (109+7)(10^9+7).

Here gcd(A1,...,AN)\gcd(A_1, ..., A_N) denotes the greatest common divisor of A1,...,ANA_1, ..., A_N.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1K1051 \leq K \leq 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

Output

Print the sum of gcd(A1,...,AN)\gcd(A_1, ..., A_N) over all KNK^N sequences, modulo (109+7)(10^9+7).


Sample Input 1Copy

Copy
3 2

Sample Output 1Copy

Copy
9

gcd(1,1,1)+gcd(1,1,2)+gcd(1,2,1)+gcd(1,2,2)\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2) +gcd(2,1,1)+gcd(2,1,2)+gcd(2,2,1)+gcd(2,2,2)+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2) =1+1+1+1+1+1+1+2=9=1+1+1+1+1+1+1+2=9

Thus, the answer is 99.


Sample Input 2Copy

Copy
3 200

Sample Output 2Copy

Copy
10813692

Sample Input 3Copy

Copy
100000 100000

Sample Output 3Copy

Copy
742202979

Be sure to print the sum modulo (109+7)(10^9+7).



2025-04-29 (Tue)
00:56:35 +00:00