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 std::fmt::Display;
use std::io::{stdin, Read};
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
use std::str::FromStr;
pub const MOD: usize = 1000_000_007;

#[derive(Clone, Copy, PartialEq, Debug, Default)]
pub struct Mint<T>(pub T);

impl Mint<usize> {
    pub fn pow(self, exp: usize) -> Self {
        let mut exp = exp;
        let mut v = self;
        let mut ret = Mint(1);
        while exp > 0 {
            if exp & 1 == 1 {
                ret *= v;
            }
            v *= v;
            exp >>= 1;
        }
        ret
    }
    pub fn inv(self) -> Self {
        self.pow(MOD - 2)
    }
}

impl<T: Display + Copy + PartialEq> Display for Mint<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl<T: FromStr + Copy + PartialEq> FromStr for Mint<T> {
    type Err = T::Err;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let v = T::from_str(s)?;
        Ok(Mint(v))
    }
}

impl Add<usize> for Mint<usize> {
    type Output = Self;
    fn add(self, rhs: usize) -> Self::Output {
        Mint((self.0 + rhs) % MOD)
    }
}

impl Add for Mint<usize> {
    type Output = Self;
    fn add(self, rhs: Self) -> Self::Output {
        self + rhs.0
    }
}

impl AddAssign<usize> for Mint<usize> {
    fn add_assign(&mut self, rhs: usize) {
        *self = *self + rhs;
    }
}

impl AddAssign for Mint<usize> {
    fn add_assign(&mut self, rhs: Self) {
        *self = *self + rhs;
    }
}

impl Sub<usize> for Mint<usize> {
    type Output = Self;
    fn sub(self, rhs: usize) -> Self::Output {
        let rhs = rhs % MOD;
        let lhs = self.0 + if self.0 < rhs { MOD } else { 0 };
        Mint(lhs - rhs)
    }
}

impl Sub for Mint<usize> {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self::Output {
        self - rhs.0
    }
}

impl SubAssign<usize> for Mint<usize> {
    fn sub_assign(&mut self, rhs: usize) {
        *self = *self - rhs
    }
}

impl SubAssign for Mint<usize> {
    fn sub_assign(&mut self, rhs: Self) {
        *self = *self - rhs
    }
}

impl Mul<usize> for Mint<usize> {
    type Output = Self;
    fn mul(self, rhs: usize) -> Self::Output {
        Mint((self.0 * rhs) % MOD)
    }
}

impl Mul for Mint<usize> {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self::Output {
        self * rhs.0
    }
}

impl MulAssign<usize> for Mint<usize> {
    fn mul_assign(&mut self, rhs: usize) {
        *self = *self * rhs;
    }
}

impl MulAssign for Mint<usize> {
    fn mul_assign(&mut self, rhs: Self) {
        *self = *self * rhs;
    }
}

impl Div<usize> for Mint<usize> {
    type Output = Self;
    fn div(self, rhs: usize) -> Self::Output {
        self * Mint(rhs).pow(MOD - 2)
    }
}

impl Div for Mint<usize> {
    type Output = Self;
    fn div(self, rhs: Self) -> Self::Output {
        self / rhs.0
    }
}

impl DivAssign<usize> for Mint<usize> {
    fn div_assign(&mut self, rhs: usize) {
        *self = *self / rhs;
    }
}
impl DivAssign for Mint<usize> {
    fn div_assign(&mut self, rhs: Self) {
        *self = *self / rhs;
    }
}
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, k: usize);
    let mut memo = vec![Mint(0); k + 1];
    fn fs(memo: &mut Vec<Mint<usize>>, m: usize, n: usize, k: usize) -> Mint<usize> {
        if memo[m] != Mint(0) {
            memo[m]
        } else {
            let mut ret = Mint(k / m).pow(n);
            for i in 2..=k {
                if i * m > k {
                    break;
                }
                ret -= fs(memo, i * m, n, k);
            }
            memo[m] = ret;
            ret
        }
    }
    let mut ret = Mint(0);
    for i in 1..=k {
        ret += fs(&mut memo, i, n, k) * i;
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}