//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define all(x) std::begin(x), std::end(x)
#define isz(x) (int)std::size(x)
const auto io_sync_off = [](){std::ios_base::sync_with_stdio(0);std::cin.tie(0);return 0;}();
// Debug defines:
#define watch(x) std::cerr << std::setw(12) << #x << " = " << std::setw(12) << x
#define watchln(x) watch(x) << std::endl
#define watchsp(x) watch(x) << " "
#define cerr cerr && debug && std::cerr
// Defines:
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = std::vector<int>;
using vl = std::vector<ll>;
using vvi = std::vector<vi>;
using vvl = std::vector<vl>;
using pii = std::pair<int,int>;
using pil = std::pair<int,ll>;
using pli = std::pair<ll,int>;
using pll = std::pair<ll,ll>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
// Comparators:
template<typename A, typename B> bool operator >(const A& a, const B& b) { return b < a; }
template<typename A, typename B> bool operator<=(const A& a, const B& b) { return !(a > b); }
template<typename A, typename B> bool operator>=(const A& a, const B& b) { return !(a < b); }
template<typename A, typename B> bool operator!=(const A& a, const B& b) { return a < b || b < a; }
template<typename A, typename B> bool operator==(const A& a, const B& b) { return !(a != b); }
namespace std {
#if __cplusplus < 201703L
    // Containers:
    template <typename T> constexpr auto size(const T& t) -> decltype(t.size()) { return t.size(); }
#endif
    // 2D arrays:
    template<typename T, int N, int M> auto size(const T (&)[N][M]) { return N * M; }
    template<typename T, int N, int M> auto begin(T (&a)[N][M]) { return &a[0][0]; }
    template<typename T, int N, int M> auto end(T (&a)[N][M]) { return &a[0][0] + N * M; }
    // 3D arrays:
    template<typename T, int N, int M, int K> auto size(const T (&)[N][M][K]) { return N * M * K; }
    template<typename T, int N, int M, int K> auto begin(T (&a)[N][M][K]) { return &a[0][0][0]; }
    template<typename T, int N, int M, int K> auto end(T (&a)[N][M][K]) { return &a[0][0][0] + N * M * K; }
    // Algorithms:
    template<typename C> void reuniq(C& c) { c.erase(unique(all(c)), end(c)); }
    template<typename C, typename X> int lowpos(const C& c, X x) {
        return int(lower_bound(all(c), x) - begin(c));
    }
    template<typename C, typename X> int uppos(const C& c, X x) {
        return int(upper_bound(all(c), x) - begin(c));
    }
    template<typename X, typename Y> X& remin(X& x, const Y& y) { return x = (y < x) ? y : x; }
    template<typename X, typename Y> X& remax(X& x, const Y& y) { return x = (x < y) ? y : x; }
}
// Numeric:
namespace Numeric {
    template<typename T, typename N> 
    T pow(T a, N n) {
        T r(1);
        while (n > 0) {
            if (n & 1) { r *= a; }
            a *= a; n >>= 1;
        }
        return r;
    }
    template<int mod>
    struct IntMod {
        int value;
        IntMod(int value_ = 0) : value(value_) {
            if (value >= mod) value -= mod;
            if (value < 0) value += mod;
        }
        IntMod& operator+=(IntMod num) {
            value += num.value;
            if (value >= mod) value -= mod;
            return *this;
        }
        IntMod& operator-=(IntMod num) {
            value -= num.value;
            if (value < 0) value += mod;
            return *this;
        }
        IntMod operator+(IntMod num) const { return IntMod(*this) += num; }
        IntMod operator-(IntMod num) const { return IntMod(*this) -= num; }
        IntMod operator*(IntMod num) const { return IntMod(int(value * 1LL * num.value % mod)); }
        IntMod& operator*=(IntMod num) { return *this = *this * num; }
        IntMod operator/(IntMod num) const { return *this * pow(num, mod-2); }
        IntMod& operator/=(IntMod num) { return *this = *this / num; }
    };
    template<int mod> bool operator<(IntMod<mod> a,IntMod<mod> b) { return a.value < b.value; }
    template<int mod>
    std::ostream& operator<<(std::ostream& os, const IntMod<mod>& num) {
        return os << num.value;
    }
}
// Rand:
namespace Rand {
    const auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
    std::mt19937 gen(seed ^ ull(std::make_unique<char>().get()));
}
// Hash:
namespace Hash {
    const ull mod = (ull(1) << 61) - 1; // prime mod of hashing
    std::vector<ull> pow{1};
    const int base = [](){
        std::uniform_int_distribution<int> dist((int)1.9e9, (int)2e9);
        int tmp = dist(Rand::gen);
        return tmp % 2 == 0 ? tmp - 1 : tmp;
    }();
    
    struct PolyHash {
        // -------- Static functions --------
        static inline ull add(ull a, ull b) {
            // Calculate (a + b) % mod, 0 <= a < mod, 0 <= b < mod
            return (a += b) < mod ? a : a - mod;
        }
        
        static inline ull sub(ull a, ull b) {
            // Calculate (a - b) % mod, 0 <= a < mod, 0 <= b < mod
            return (a -= b) < mod ? a : a + mod;
        }

        static inline ull mul(ull a, ull b){
            // Calculate (a * b) % mod, 0 <= a < mod, 0 <= b < mod
            ull l1 = (uint32_t)a, h1 = a >> 32, l2 = (uint32_t)b, h2 = b >> 32;
            ull l = l1*l2, m = l1*h2 + l2*h1, h = h1*h2;
            ull ret = (l & mod) + (l >> 61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
            ret = (ret & mod) + (ret >> 61);
            ret = (ret & mod) + (ret >> 61);
            return ret-1;
        }
        
        // -------- Variables of class --------
        std::vector<ull> pref; // polynomial hash on prefix
        
        // Constructor from string:
        PolyHash(const std::string& s) 
            : pref(s.size()+1u, 0) 
        {
            // Pre-calculate powers of base:
            while (pow.size() <= s.size()) {
                pow.push_back(mul(pow.back(), base));
            }
            // Calculate polinomial hash on prefix:
            for (int i = 0; i < (int)s.size(); ++i) {
                pref[i+1] = add(mul(pref[i], base), s[i]);
            }
        }
        
        // Constructor from vector:
        template<typename T> PolyHash(const std::vector<T>& v) 
            : pref(v.size()+1u, 0) 
        {
            // Pre-calculate powers of base:
            while (pow.size() <= v.size()) {
                pow.push_back(mul(pow.back(), base));
            }
            // Calculate polinomial hash on prefix:
            for (int i = 0; i < (int)v.size(); ++i) {
                pref[i+1] = add(mul(pref[i], base), v[i]);
            }
        }
        
        // Get hash from [pos, pos+len-1] segment of string
        inline ull operator()(const int pos, const int len) const {
            return sub(pref[pos+len], mul(pref[pos], pow[len]));
        }
    };
}
// Input:
template<typename T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (auto &it : vec) is >> it;
    return is;
}
// Output:
template<typename A, typename B> std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& pt) {
    return os << "{" << pt.first << ", " << pt.second << "}";
}
#define DEFINE_INSERT(Cont, Method) template<typename X, typename... T> \
Cont<T...>& operator<<(Cont<T...>& c, const X& x) { return c.Method(x), c; }
DEFINE_INSERT(std::set, insert)
DEFINE_INSERT(std::multiset, insert)
DEFINE_INSERT(std::vector, push_back)
DEFINE_INSERT(std::list, push_back)
DEFINE_INSERT(std::deque, push_back)
DEFINE_INSERT(std::priority_queue, push)
DEFINE_INSERT(std::queue, push)
DEFINE_INSERT(std::stack, push)
#undef DEFINE_INSERT

template<typename Iterator>
std::ostream& print_range(std::ostream& os, Iterator begin, Iterator end) {
	os << "{";
	for (bool first = 1; begin != end; os << *begin++) {
		if (!first) os << ", ";
		first = 0;
	}
	return os << "}";
}
 
#define DEFINE_OUTPUT(container) template<typename... T> \
std::ostream& operator<<(std::ostream& os, const container<T...>& v) { \
	return print_range(os, v.begin(), v.end()); \
}
DEFINE_OUTPUT(std::vector)
DEFINE_OUTPUT(std::list)
DEFINE_OUTPUT(std::set)
DEFINE_OUTPUT(std::multiset)
DEFINE_OUTPUT(std::deque)
#undef DEFINE_OUTPUT
 
#define DEFINE_OUTPUT(container, get, rem) template<typename T, typename... C> \
std::ostream& operator<<(std::ostream& os, container<T, C...> q) { \
	std::vector<T> v; \
	while (q.size()) v << q.get(), q.rem();\
	return os << v; \
}
DEFINE_OUTPUT(std::priority_queue, top, pop)
DEFINE_OUTPUT(std::queue, front, pop)
DEFINE_OUTPUT(std::stack, top, pop)
#undef DEFINE_OUTPUT
// Variables:
//const int debug = 0;
// -----------------------------------------------------------------------------
const int mod = (int)1e9+7;
using namespace Numeric;
using Int = IntMod<mod>;
template<bool debug = 0>
Int slow(int n, int k) {
    assert(n == 3);
    Int sum = 0;
    std::vector<Int> dp(1+k);
    for (int a = 1; a <= k; a++)
        for (int b = 1; b <= k; b++)
            for (int c = 1; c <= k; c++) {
                int g = std::__gcd(a,b);
                g = std::__gcd(g,c);
                dp[g]+=1;
                sum += g;
            }
    watchln(dp);
    return sum;
}
template<bool debug = 0>
Int fast(int n, int k) {
    std::vector<Int> dp(1+k);
    for (int x = k; x >= 1; x--) {
        Int answ(0);
        Int cnt(1);
        for (int y = 2 * x; y <= k; y+=x) {
            answ -= dp[y]; cnt+=1;
        }
        watchln(x);
        watchln(cnt);
        watchln(answ);
        answ += pow(cnt,n);
        watchln(answ);
        dp[x] = answ;
    }
    watchln(dp);
    Int answ(0);
    for (int x = 1; x <= k; x++) {
        answ += dp[x] * x;
    }
    return answ;
}
void test() {
    for (int k = 1; k <= 200; k++) {
        if (fast(3, k) != slow(3, k)) {
            std::cout << "k = " << k << std::endl;
            std::cout << "fast = " << fast<1>(3,k) << std::endl;
            std::cout << "slow = " << slow<1>(3,k) << std::endl;
            std::exit(0);
        }
    }
    std::cout << "ok" << std::endl;
    std::exit(0);
}
int main() {
    //test();
    int n, k; 
    while (std::cin >> n >> k) {
        std::cout << fast(n,k) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3724