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)

pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}

#[allow(dead_code)]
fn gcd(a: u32, b: u32) -> u32 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

const MOD :u64 = 1_000_000_007;

#[allow(dead_code)]
fn pow(mut x: u64, mut y: u64) -> u64 {
    let mut r = 1;
    while y > 0{
        if (y&1) == 1{
            r = r*x%MOD;
        }
        y >>= 1;
        x = x*x%MOD;
    }
    r
}


fn main(){
    let mut scan = Scanner::new();
    let n:usize = scan.next();
    let k:usize = scan.next();
    let mut v:Vec<u64> = vec![0; k + 1];

    for i in (1..k+1).rev(){
        let m:u64 = (k / i) as u64; 
        v[i] = pow(m, n as u64);

        let mut j = 2;
        while i*j <= k {
            if v[i] >= v[i*j]{
                v[i] -= v[i*j];
            }else{
                v[i] = MOD - v[i*j] + v[i];
            }
            j += 1;
        }
    }
    let mut ans = 0;
    for i in 1..k+1{
        ans += v[i] * i as u64;
        ans %= MOD;
    }
    println!("{}", ans);
}