#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10, p = 1e9 + 7;
int n, k, f[N];
vector<int> ys[N];
int pri[N / 10], pnum, bo[N], fp[N];
inline int qmi(int x, int y) {
  int ans = 1;
  for (; y; y >>= 1, x = 1ll * x * x % p)
    if (y & 1) ans = 1ll * ans * x % p;
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 2; i <= k; ++i) {
    if (!bo[i]) fp[i] = i, pri[++pnum] = i;
    for (int j = 1; j <= pnum && i * pri[j] <= k; ++j) {
      bo[i * pri[j]] = 1;
      fp[i * pri[j]] = pri[j];
      if (i % pri[j] == 0) break;
    }
  }
  int ans = 0;
  ys[1].push_back(1);
  f[1] = 1;
  for (int i = 2; i <= k; ++i) {
    vector<int> &g = ys[i] = ys[i / fp[i]];
    int s = g.size();
    g.resize(s * 2);
    for (int j = 0; j < s; ++j) g[j + s] = g[j] * fp[i];
    inplace_merge(g.begin(), g.begin() + s, g.end());
    g.erase(unique(g.begin(), g.end()), g.end());
    f[i] = (f[i - 1] + qmi(i, n) - qmi(i - 1, n)) % p;
    for (int j = 1; j < g.size(); ++j) {
      f[i] = (f[i] - f[i / g[j]] + f[i / g[j] - 1]) % p;
    }
    f[i] = (f[i] + p) % p;
    ans = (ans + (f[i] ^ i)) % p;
  }
  printf("%d", ans);
  return 0;
}
