#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e6 + 5;
long long n, k, ans[N], odd_even[N];
vector<int> vc[N];
long long binpw(long long base, long long pw) {
  long long ans = 1;
  while (pw) {
    if (pw & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    pw >>= 1;
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    ans[i] = (binpw(i, n) - binpw(i - 1, n) + mod) % mod;
  for (long long i = 1; i <= k; i++) {
    for (long long j = i * i; j <= k; j += i) vc[j].push_back(i);
  }
  for (int i = 2; i <= k; i++) {
    if (vc[i].size() >= 1)
      odd_even[i] = odd_even[vc[i][0]] ^ 1;
    else
      odd_even[i] = 1;
    if (!odd_even[i]) odd_even[i]--;
    odd_even[i] = -odd_even[i];
  }
  for (int i = 2; i <= k; i++) {
    ans[i]--;
    for (int j = 1; j < vc[i].size(); j++) {
      ans[i] -= ans[vc[i][j]];
      if (ans[i] < 0) ans[i] += mod;
      if (ans[i] >= mod) ans[i] -= mod;
      if (vc[i][j] * vc[i][j] == i) continue;
      ans[i] -= ans[i / vc[i][j]];
      if (ans[i] < 0) ans[i] += mod;
      if (ans[i] >= mod) ans[i] -= mod;
    }
  }
  long long tol = 0, sum = 0;
  for (int i = 1; i <= k; i++) {
    sum = (sum + ans[i]) % mod;
    tol += (sum ^ i);
    tol %= mod;
  }
  cout << tol;
}
