#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
long long add(long long x, long long y) {
  x += y;
  if (x >= MOD) return x - MOD;
  return x;
}
long long sub(long long x, long long y) {
  x -= y;
  if (x < 0) return x + MOD;
  return x;
}
long long mult(long long x, long long y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
int lpf[2000005];
int mob[2000005];
void sieve_lowest_pf() {
  for (int i = 2; i <= 2000001; ++i) {
    if (lpf[i] == 0) {
      lpf[i] = i;
      for (int j = i * 2; j <= 2000001; j += i) {
        if (lpf[j] == 0) lpf[j] = i;
      }
    }
  }
}
void mobius_from_lpf() {
  mob[1] = 1;
  for (int i = 2; i <= 2000001; ++i) {
    int j = i / lpf[i];
    if (lpf[j] == lpf[i])
      mob[i] = 0;
    else
      mob[i] = -mob[j];
  }
}
int mod_exp(long long x, int e) {
  long long ans = 1;
  while (e > 0) {
    if (e & 1) ans = mult(ans, x);
    x = mult(x, x);
    e >>= 1;
  }
  return ans;
}
int pows[2000005];
void pre_powers(int n) {
  pows[0] = 0;
  for (int i = 1; i <= 2000000; ++i) {
    pows[i] = mod_exp(i, n);
  }
}
int ans[2000005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin >> n >> k;
  sieve_lowest_pf();
  mobius_from_lpf();
  pre_powers(n);
  for (int i = 1; i <= k; ++i) {
    for (int j = i; j <= k; j += i) {
      ans[j] = add(ans[j], sub(mob[i] * pows[j / i], 0));
      if (j + i <= k)
        ans[j + i] = sub(ans[j + i], sub(mob[i] * pows[j / i], 0));
    }
  }
  for (int i = 1; i <= k; ++i) ans[i] = add(ans[i], ans[i - 1]);
  int res = 0;
  for (int i = 1; i <= k; ++i) res = add(res, ans[i] ^ i);
  cout << res << endl;
  return 0;
}
