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::io;
use std::str::FromStr;

static MOD: u64 = 1_000_000_007;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn binary_power(x: u64, n: u64) -> u64 {
    if n == 0 {
      return 1;
    }
    if n % 2 == 0 {
      return (binary_power(x, n / 2) % MOD).pow(2) % MOD;
    } else {
      return binary_power(x, n - 1) % MOD * x % MOD;
    }
}

fn main() {
    let (n, k) = input_tuple();
    let mut multiples: Vec<u64> = Vec::new();

    multiples.push(0);
    for i in 1..(k+1) {
        multiples.push(k / i);
    }

    let mut ans: Vec<u64> = Vec::new();
    ans.push(0);
    for i in 1..(k+1) {
        ans.push(binary_power(multiples[i as usize], n));
    }

    // println!("{:?}", multiples);

    // println!("{:?}", ans);

    for i in (1..(k+1)).rev() {
        let mut num = 2;
        for j in 2..(k/i+1) {
            ans[i as usize] = (ans[i as usize] + MOD - ans[(i * j) as usize]) % MOD;
        }
    }

    // println!("{:?}", ans);

    let mut sum = 0;
    for i in 1..ans.len() {
        sum += ans[i] * i as u64 % MOD;
        sum %= MOD;
    }
    println!("{}", sum);
}