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::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Chars, Bytes};
#[allow(unused_imports)]
use num::integer::gcd;
#[allow(unused_imports)]
use std::mem::swap;

#[allow(dead_code)]
type Pi = (i32, i32);
#[allow(dead_code)]
fn pri<T: std::fmt::Display>(x: T) {println!("{}", x);}

// Modint
const MOD: u32 = 1000000007;
#[derive(Clone, Copy)]
struct Mint(u32);
impl std::ops::Add for Mint {
    type Output = Mint;
    fn add(self, x: Mint) -> Mint {
        let res = self.0 + x.0;
        Mint(if res >= MOD {res-MOD} else {res})
    }
}
impl std::ops::AddAssign for Mint {
    fn add_assign(&mut self, x: Mint) {
        *self = *self + x;
    }
}
impl std::ops::Sub for Mint {
    type Output = Mint;
    fn sub(self, x: Mint) -> Mint {
        let res = self.0 + MOD - x.0;
        Mint(if res >= MOD {res-MOD} else {res})
    }
}
impl std::ops::SubAssign for Mint {
    fn sub_assign(&mut self, x: Mint) {
        *self = *self - x;
    }
}
impl std::ops::Mul for Mint {
    type Output = Mint;
    fn mul(self, x: Mint) -> Mint {Mint((self.0 as u64 * x.0 as u64 % MOD as u64) as u32)}
}
impl std::ops::MulAssign for Mint {
    fn mul_assign(&mut self, x: Mint) {
        *self = *self * x;
    }
}
impl std::ops::Div for Mint {
    type Output = Mint;
    fn div(self, x: Mint) -> Mint {
        let mut a = x.0 as i64; //solves au + mv = 1 and u = a^-1
        let mut m = MOD as i64; let mut u = 1i64; let mut v = 0i64;
        let mut buf: i64;
        while m != 0 {
            let t = a / m;
            a -= t * m; buf = a; a = m; m = buf;
            u -= t * v; buf = u; u = v; v = buf;
        }
        u %= m;
        if u < 0 {u += m;}
        self * Mint(u as u32)
    }
}
impl std::ops::DivAssign for Mint {
    fn div_assign(&mut self, x: Mint) {
        *self = *self / x;
    }
}
impl std::fmt::Display for Mint {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
impl Mint {
    pub fn pow(self, mut n: u32) -> Mint {
        let mut res = Mint(1); let mut r = self;
        while n > 0 {
            if n & 1 == 1 {res *= r;}
            r *= r;
            n >>= 1;
        }
        res
    }
    #[allow(dead_code)]
    pub fn inv(self) -> Mint {
        assert!(self.0 > 0);
        self.pow(MOD - 2)
    }
}

#[fastout]
fn main() {
    input!{
        n: u32, k: u32,
    }
    let mut v: Vec<Mint> = Vec::new(); for _ in 0..k+1 {v.push(Mint(0));}
    for i in (1..k+1).rev() {
        v[i as usize] += Mint(k/i).pow(n);
        let mut j = i * 2;
        while j <= k {
            let x = v[j as usize];
            v[i as usize] -= x;
            j += i;
        }
    }
    let mut ans = Mint(0);
    for i in 1..k+1 {
        ans += v[i as usize] * Mint(i);
    }
    pri(ans);
}