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)

#![allow(non_snake_case)]
use proconio::input;

#[rustfmt::skip]
fn main() { std::thread::Builder::new().stack_size(128 * 1024 * 1024).spawn(solve).unwrap().join().unwrap(); }

static MOD: i64 = 1_000_000_007;

#[proconio::fastout]
fn solve() {
    input! {
        N: i64, K:usize
    }

    let mut dp = vec![0; K + 1];
    for k in (1..=K).rev() {
        dp[k] = modpow((K / k) as i64, N, MOD);
        for x in (2 * k..=K).step_by(k) {
            dp[k] -= dp[x]
        }
        dp[k] %= MOD;
        dp[k] += MOD;
        dp[k] %= MOD;
    }

    println!(
        "{}",
        dp.iter()
            .enumerate()
            .map(|(i, &x)| i as i64 * x % MOD)
            .sum::<i64>()
            % MOD
    );
}

fn modpow(a: i64, b: i64, m: i64) -> i64 {
    if b == 0 {
        1
    } else if b % 2 == 0 {
        let x = modpow(a, b / 2, m);
        x * x % m
    } else {
        a * modpow(a, b - 1, m) % m
    }
}