#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10, Mod = 1e9 + 7;
long long Pow(long long x, long long e) {
  long long ret = 1;
  while (e) {
    if (e & 1) ret = ret * x % Mod;
    x = x * x % Mod;
    e >>= 1;
  }
  return ret;
}
int prm[N], mu[N], tot;
void init(int n) {
  mu[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!prm[i]) prm[++tot] = i, mu[i] = -1;
    for (int j = 1; j <= tot && i * prm[j] <= n; ++j) {
      prm[i * prm[j]] = true;
      if (i % prm[j])
        mu[i * prm[j]] = -mu[i];
      else
        break;
    }
  }
}
int n, k;
long long delt[N], g[N];
int main() {
  scanf("%d%d", &n, &k);
  init(k + 5);
  for (int i = 1; i <= k; i++) g[i] = Pow(i, n);
  for (int i = 1; i <= k; i++)
    for (int j = 1; i * j <= k; ++j)
      (delt[i * j] += Mod + mu[i] * (g[j] - g[j - 1])) %= Mod;
  long long now = 0, ans = 0;
  for (int i = 1; i <= k; i++) (now += delt[i]) %= Mod, (ans += now ^ i) %= Mod;
  cout << ans << endl;
  return 0;
}
