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 <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

constexpr inline ll mod = 1'000'000'007;

constexpr inline int max_n = 100'000 + 5;
vector<ll> xs(max_n + 1); // xs[d] = #{ d % gcd == 0 }
vector<ll> ys(max_n + 1); // ys[d] = #{ d == gcd }

ll modpow(ll x, int y) {
    if (y == 0) { return 1; }
    if (y % 2 == 0) {
        ll res = modpow(x, y/2);
        return res * res % mod;
    } else {
        return modpow(x, y-1) * x % mod;
    }
}

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    int n,k;
    cin >> n >> k;

    ll res = 0;
    for (int d = 1; d <= k; d++) {
        ll c = k / d; // 倍数の個数
        xs[d] = modpow(c, n);
    }
    for (int d = k; d >= 1; d--) {
        ys[d] = xs[d];
        for (int i = 2; d * i <= k; i++) {
            int d2 = d * i;
            ys[d] -= ys[d2] - mod;
            ys[d] %= mod;
        }
    }
    for (int d = 1; d <= k; d++) {
        res += d * ys[d];
        res %= mod;
    }
    cout << res << endl;

    return 0;
}