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(unused_imports)]
use num::Integer;
use proconio::*;
use std::collections::VecDeque;
use std::ops::*;

fn main() {
   input! {
      n: usize,
      k: usize
   }
   let mut ans = Mint::new(0);
   let mut dp = vec![Mint::new(0); k+1];
   for i in (1..=k).rev() {
      let mut val = Mint::new((k/i) as i64).pow(n);
      for j in 2..=k/i {
         val -= dp[i*j];
      }
      dp[i] = val;
      ans += Mint::from(i)*dp[i];
   }
   println!("{}", ans.x);
}

const MOD: i64 = 1000000007;
#[derive(Copy, Clone, Debug)]
struct Mint {
   x: i64,
}
impl Mint {
   fn new(x: i64) -> Self {
      Mint { x: x }
   }
   fn pow(self, n: usize) -> Self {
      let mut x = Mint::new(1);
      let mut r = self;
      let mut n = n;
      while n > 0 {
         if n & 1 == 1 {
            x *= r;
         }
         r *= r;
         n >>= 1;
      }
      x
   }
   fn inv(self) -> Self {
      self.pow((MOD - 2) as usize)
   }
}
impl AddAssign for Mint {
   fn add_assign(&mut self, rhs: Mint) {
      self.x += rhs.x;
      self.x %= MOD;
   }
}
impl Add for Mint {
   type Output = Mint;
   fn add(self, other: Mint) -> Self {
      let mut res = self;
      res += other;
      res
   }
}

impl SubAssign for Mint {
   fn sub_assign(&mut self, rhs: Mint) {
      self.x -= rhs.x;
      if self.x < 0 {
         self.x += MOD;
      }
   }
}
impl Sub for Mint {
   type Output = Mint;
   fn sub(self, other: Mint) -> Self {
      let mut res = self;
      res -= other;
      res
   }
}
impl MulAssign for Mint {
   fn mul_assign(&mut self, rhs: Mint) {
      self.x *= rhs.x;
      self.x %= MOD;
   }
}
impl Mul for Mint {
   type Output = Mint;
   fn mul(self, other: Mint) -> Self {
      let mut res = self;
      res *= other;
      res
   }
}
impl DivAssign for Mint {
   fn div_assign(&mut self, rhs: Mint) {
      *self *= rhs.inv();
   }
}
impl Div for Mint {
   type Output = Mint;
   fn div(self, other: Mint) -> Self {
      let mut res = self;
      res *= other;
      res
   }
}
impl From<i64> for Mint {
   fn from(num: i64) -> Self {
      Mint { x: num }
   }
}
impl From<i32> for Mint {
   fn from(num: i32) -> Self {
      Mint { x: num as i64 }
   }
}
impl From<usize> for Mint {
   fn from(num: usize) -> Self {
      Mint { x: num as i64 }
   }
}