#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
const long long MOD = 1e9 + 7;
int n, k, mu[N];
long long pw[N], sum[N];
vector<int> prime;
bool not_prime[N];
int size, head[N], nxt[N * 9], val[N * 9];
void add(int u, int x) {
  nxt[size] = head[u];
  val[size] = x;
  head[u] = size++;
}
long long pow_mod(long long x, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
void process() {
  for (int i = 1; i <= k; i++) {
    pw[i] = pow_mod(i, n);
  }
  not_prime[1] = 1;
  mu[1] = -1;
  memset(head, -1, sizeof(head));
  for (int i = 2; i <= k; i++) {
    if (!not_prime[i]) {
      prime.push_back(i);
      mu[i] = 1;
    }
    for (int j = 0; j < prime.size(); j++) {
      int x = prime[j] * i;
      if (x > k) break;
      not_prime[x] = 1;
      if (i % prime[j] == 0) {
        mu[x] = 0;
        break;
      }
      mu[x] = -mu[i];
    }
  }
  for (int i = 2; i <= k; i++) {
    if (!mu[i]) continue;
    for (int j = i; j <= k; j += i) {
      add(j, i);
    }
  }
}
long long solve() {
  for (int i = 1; i <= k; i++) {
    sum[i] = sum[i - 1];
    for (int j = head[i]; j != -1; j = nxt[j]) {
      int x = val[j];
      sum[i] = (sum[i] + (pw[i / x] - pw[i / x - 1]) * mu[x] + MOD) % MOD;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= k; i++) {
    sum[i] = (pw[i] - sum[i] + MOD) % MOD;
    ans = (ans + (sum[i] ^ i)) % MOD;
  }
  return ans;
}
int main() {
  scanf("%d %d", &n, &k);
  process();
  printf("%lld\n", solve());
}
