mod fp {
    use std::ops::{Add, AddAssign, Sub, SubAssign, Mul, MulAssign, Div, DivAssign};
    use num::One;
    pub trait ConstUSize {
        const VALUE: usize;
    }

    #[derive(Clone, Copy, PartialEq, Eq, Debug)]
    pub struct C10E9_7;
    impl ConstUSize for C10E9_7 {
        const VALUE: usize = 1000000007;
    }

    #[derive(Clone, Copy, PartialEq, Eq, Debug)]
    pub struct Fp<C> {
        v: usize,
        phantom: std::marker::PhantomData<C>,
    }

    impl<C:ConstUSize> Fp<C> {
        fn p() -> usize {
            C::VALUE
        }

        pub fn value(&self) -> usize {
            self.v
        }

        pub fn new(v: usize) -> Self{
            Self {
                v: v % Self::p(),
                phantom: std::marker::PhantomData,
            }
        }
    }

    impl<C:ConstUSize> From<usize> for Fp<C> {
        fn from(v: usize) -> Self {
            Self::new(v)
        }   
    }

    impl<C:ConstUSize> Into<usize> for Fp<C> {
        fn into(self) -> usize {
            self.v
        }
    }

    impl<C:ConstUSize> Add for Fp<C> {
        type Output = Self;
        fn add(self, other: Self) -> Self {
            (self.v as usize + other.v).into()
        }
    }

    impl<C:ConstUSize> AddAssign for Fp<C> where Self: Clone {
        fn add_assign(&mut self, other: Self) {
            *self = self.clone() + other;
        }
    }

    impl<C:ConstUSize> Sub for Fp<C> {
        type Output = Self;
        fn sub(self, other: Self) -> Self {
            (self.v as usize + Self::p() - other.v).into()
        }
    }

    impl<C:ConstUSize> SubAssign for Fp<C> where Self: Clone {
        fn sub_assign(&mut self, other: Self) {
            *self = self.clone() - other;
        }
    }

    impl<C:ConstUSize> Mul for Fp<C> {
        type Output = Self;
        fn mul(self, other: Self) -> Self {
            (self.v as usize * other.v).into()
        }
    }

    impl<C:ConstUSize> MulAssign for Fp<C> where Self: Clone {
        fn mul_assign(&mut self, other: Self) {
            *self = self.clone() * other;
        }
    }

    impl<C:ConstUSize> One for Fp<C> {
        fn one() -> Self {
            Self::new(1)
        }
    }

    impl<C:ConstUSize> Div for Fp<C> where Self: Clone {
        type Output = Self;
        fn div(self, other: Self) -> Self {
            let inv = num::pow::pow(other, Self::p() - 2);
            self * inv
        }
    }

    impl<C:ConstUSize> DivAssign for Fp<C> where Self: Clone {
        fn div_assign(&mut self, other: Self) {
            *self = self.clone() / other;
        }
    }
}

type F = fp::Fp<fp::C10E9_7>;
fn main() {
    use num::pow::pow;
    proconio::input! {
        n: usize,
        k: usize,
    }

    let mut counts = vec![F::new(0); k + 1];
    for i in (1..=k).rev() {
        counts[i] = pow(F::new(k / i), n);
        for j in 1..=k {
            if i * (j + 1) <= k {
                let s = counts[i * (j+1)];
                counts[i] -= s;
            } else {
                break;
            }
        }
    }

    let sum: F = counts.iter().enumerate().map(|(i, c)| F::new(i) * *c)
        .fold(0.into(), std::ops::Add::add);

    println!("{}", sum.value());
}


Measured memory_bytes: 2784