#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;
const double eps = 1e-6;
const double PI = acos(-1);
int n, k, miu[N], Pown[N], sum[N];
int Power(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % mod;
    a = 1LL * a * a % mod;
    b >>= 1;
  }
  return ans;
}
int main() {
  miu[1] = 1;
  for (int i = 1; i < N; i++)
    for (int j = i + i; j < N; j += i) miu[j] -= miu[i];
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) Pown[i] = Power(i, n);
  int ans = 0, tmp = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = i; j <= k; j += i) {
      sum[j] =
          ((sum[j] + 1LL * miu[i] * (Pown[j / i] - Pown[j / i - 1])) % mod +
           mod) %
          mod;
    }
    tmp = (tmp + sum[i]) % mod;
    ans = (ans + (tmp ^ i)) % mod;
  }
  printf("%d\n", ans);
  return 0;
}
