#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * inf;
const int N = 2000000 + 7;
const int M = 1600;
const int multipleTest = 0;
const double pi = acos(-1);
class FenWickTree {
 public:
  static const int MAXN = N;
  int L[MAXN];
  void update(int x, int val) {
    L[x] += val;
    if (L[x] >= inf) L[x] -= inf;
    if (L[x] < 0) L[x] += inf;
  }
  int get(int x) {
    L[x] += L[x - 1];
    if (L[x] >= inf) L[x] -= inf;
    return L[x];
  }
} fenwickTree;
int pw(int x, int k) {
  if (!k) return 1;
  if (k & 1) return 1ll * pw(x, k ^ 1) * x % inf;
  long long res = pw(x, k >> 1);
  return res * res % inf;
}
int n, k;
int res = 0;
vector<pair<int, int> > sub[N];
int a[N];
void solve() {
  cin >> n >> k;
  for (int i = (1), _b = (k + 1); i < _b; ++i) {
    int old = fenwickTree.get(i) + pw(i, n);
    if (old >= inf) old -= inf;
    if (i > 1) old -= 1;
    if (old < 0) old += inf;
    for (int j = i, t = 1; j <= k; j += i, ++t) {
      if (t >= i) {
        sub[t].push_back(make_pair(j, min(k, j + i - 1)));
      } else {
        fenwickTree.update(max(j, i + 1), -a[t]);
        fenwickTree.update(min(k, j + i - 1) + 1, a[t]);
      }
    }
    for (pair<int, int> x : sub[i]) {
      fenwickTree.update(x.first, -old);
      fenwickTree.update(x.second + 1, old);
    }
    a[i] = old;
    res = (res + (old ^ i)) % inf;
  }
  cout << res << '\n';
}
int main() {
  int Test = 1;
  if (multipleTest) cin >> Test;
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}
