#include <bits/stdc++.h>
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
struct debug {
  template <class T>
  debug& operator<<(const T&) {
    return *this;
  }
};
using ll = long long;
template <typename T>
void min_self(T& a, T b) {
  a = min(a, b);
}
template <typename T>
void max_self(T& a, T b) {
  a = max(a, b);
}
const int mod = 1e9 + 7;
inline int add(int a, int b) {
  a += b;
  while (a >= mod) a -= mod;
  while (a < 0) a += mod;
  return a;
}
inline void add_self(int& a, int b) { a = add(a, b); }
inline int mul(int a, int b) { return 1LL * a * b % mod; }
inline void mul_self(int& a, int b) { a = mul(a, b); }
inline int mpow(int a, int n) {
  int res = 1;
  while (n > 0) {
    if (n & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    n >>= 1;
  }
  return res;
}
inline int divide(int a, int b) {
  assert(b != 0);
  return mul(a, mpow(b, mod - 2));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> bad(k + 1), c(k + 1);
  vector<bool> square_free(k + 1, true), siv(k + 1, true);
  for (int i = 2; i <= k; i++) {
    if (siv[i]) {
      ++c[i];
      for (int j = 2 * i; j <= k; j += i) {
        siv[j] = false;
        if (j % (1LL * i * i) == 0) {
          square_free[j] = false;
        }
        ++c[j];
      }
    }
    if (square_free[i]) {
      c[i] = c[i] % 2 == 1 ? 1 : -1;
    }
  }
  vector<int> powers(k + 1);
  for (int i = 1; i <= k; i++) {
    powers[i] = mpow(i, n);
  }
  for (int i = 2; i <= k; i++) {
    if (!square_free[i]) {
      continue;
    }
    for (int j = i; j <= k; j += i) {
      add_self(bad[j], mul(c[i], powers[j / i]));
      if (j > i) {
        add_self(bad[j], -mul(c[i], powers[j / i - 1]));
      }
    }
  }
  for (int i = 1; i <= k; i++) {
    add_self(bad[i], bad[i - 1]);
  }
  int ans = 0;
  for (int i = 1; i <= k; i++) {
    int cur = powers[i];
    add_self(cur, -bad[i]);
    add_self(ans, cur ^ i);
  }
  cout << ans << '\n';
}
