Problem:
Score : 500 points

Problem Statement

Consider sequences \{A_1,...,A_N\} of length N consisting of integers between 1 and K (inclusive).

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

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

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

Constraints

2 \leq N \leq 10^5

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

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

Sample Input 1

3 2

Sample Output 1

9

\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)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

3 200

Sample Output 2

10813692

Sample Input 3

100000 100000

Sample Output 3

742202979

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

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

ll powmod(ll a, ll b){
	if(b == 0) return 1;
	if(b & 1) {
		return a * powmod(a, b - 1) % MOD;
	} else {
		ll d = powmod(a, b / 2) % MOD;
		return d * d % MOD;
	}
}

ll sub(ll a, ll b){
	return a + MOD - b;
}

ll inv(ll a){
	return powmod(a, MOD - 2);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n, k;
	cin >> n >> k;

	ll ans = 0;
	vector<ll> dp(k + 1, 0);
	for(ll i = k; i >= 1; i--){
		ll t = powmod(k / i, n);
		for(ll j = 2 * i; j <= k; j += i){
			t += MOD - dp[j];
			t %= MOD;
		}
		ans += i * t % MOD;
		ans %= MOD;

		dp[i] = t;
	}

	cout << ans << endl;
}