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: Time Limit Exceeded)

#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]
use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, stdin, BufRead};
use std::str::FromStr;

fn read_one<T>() -> T
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let stdin = stdin();
    let mut handle = stdin.lock();
    let mut buf = String::new();
    handle.read_line(&mut buf).unwrap();

    buf.trim().parse::<T>().unwrap()
}

macro_rules! read_tuple {
        ( $( $t:ty ), * ) => {
            {
                let stdin = stdin();
                let mut handle = stdin.lock();
                let mut buf = String::new();
                handle.read_line(&mut buf).unwrap();
                let mut v = buf.trim().split_whitespace()
                    .collect::<VecDeque<&str>>();
                (
                    $({
                        v.pop_front().unwrap().parse::<$t>().unwrap()
                    },)*
                )
            }
        }
    }

fn read_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let stdin = stdin();
    let mut handle = stdin.lock();
    let mut buf = String::new();
    handle.read_line(&mut buf).unwrap();

    buf.trim()
        .split_whitespace()
        .map(|s| s.parse::<T>().unwrap())
        .collect::<Vec<T>>()
}

fn get_gcd(a: i32, b: i32) -> i32 {
    if a < b {
        return get_gcd(b, a);
    } else if b == 0 {
        return a;
    } else {
        return get_gcd(b, a % b);
    }
}
fn get_gcd2(v: &Vec<i32>, l: usize, r: usize) -> i32 {
    if (r - l == 2) {
        get_gcd(v[l], v[l + 1])
    } else if (r - l == 1) {
        v[l]
    } else {
        let m = (l + r) / 2;
        let g1 = get_gcd2(v, l, m);
        if g1 == 1 {
            1
        } else {
            let g2 = get_gcd2(v, m, r);
            get_gcd(g1, g2)
        }
    }
}

fn rec(v: &mut Vec<i32>, k: i32, idx: usize, sum: &mut i32) {
    if idx == v.len() {
        *sum += get_gcd2(v, 0, v.len());
    } else {
        for i in 1..k+1 {
            v[idx] = i;
            rec(v, k, idx + 1, sum);
        }
    }
}

fn main() -> io::Result<()> {
    let (n, k) = read_tuple![i32, i32];
    let mut v: Vec<i32> = (0..n).map(|_| 0).collect();
    let mut sum = 0;
    rec(&mut v, k, 0, &mut sum);
    println!("{}", sum);

    return Ok(());
}