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 Rust (1.42.0) (judge verdict: Accepted)

use proconio::input;
use std::collections::HashMap;

const MOD: i64 = 1000000007;


fn main() {
    input! {
        n: i64,
        k: i64,
    }

    let mut ans: i64 = 0;

    let mut log: HashMap<i64, i64> = HashMap::new();

    for x in 0..k {
        let x = k - x;

        let mut res_x = calc(k, n, x);

        let mut i = 2;
        while i * x <= k {
            res_x -= log.get(&(i * x)).unwrap();
            if res_x < 0 {
                res_x += MOD;
            }
            i += 1;
        }

        log.insert(x, res_x);

        ans += res_x * x;
        ans %= MOD;
    }

    println!("{}", ans);
}


fn mod_pow(mut a: i64, mut n: i64, m: i64) -> i64 {
    let mut res = 1;
    while n > 0 {
        if (n & 1) == 1 {
            res = res * a % m;
        }
        a = a * a % m;
        n >>= 1;
    }
    res
}


fn calc(k: i64, n: i64, x: i64) -> i64 {
    mod_pow(k / x, n, MOD)
}