#include <bits/stdc++.h>
using namespace std;
int n, k, i, j, ans[2000005], mu[2000005], vis[2000005], prime[2000005],
    pw[2000005];
int power(int x, int y) {
  int sum = 1;
  for (; y; y >>= 1) {
    if (y & 1) sum = 1ll * sum * x % 1000000007;
    x = 1ll * x * x % 1000000007;
  }
  return sum;
}
int main() {
  scanf("%d%d", &k, &n);
  mu[1] = 1;
  for (i = 2; i < 2000005; ++i) {
    if (!vis[i]) {
      vis[i] = 1;
      prime[++prime[0]] = i;
      mu[i] = -1;
    }
    for (j = 1; i * prime[j] < 2000005; ++j) {
      vis[i * prime[j]] = 1;
      if (i % prime[j] == 0) {
        mu[i * prime[j]] = 0;
        break;
      }
      mu[i * prime[j]] = -mu[i];
    }
  }
  for (i = 0; i <= n; ++i) pw[i] = power(i, k);
  for (i = 1; i < 2000005; ++i)
    if (mu[i] == -1) mu[i] += 1000000007;
  for (i = 1; i <= n; ++i)
    if (mu[i]) {
      for (j = i; j <= n; j += i) {
        (ans[j] += 1ll * mu[i] * pw[j / i] % 1000000007) %= 1000000007;
        (ans[j] -= 1ll * mu[i] * pw[j / i - 1] % 1000000007) %= 1000000007;
        if (ans[j] < 0) ans[j] += 1000000007;
      }
    }
  for (i = 1; i <= n; ++i) (ans[i] += ans[i - 1]) %= 1000000007;
  for (i = 1; i <= n; ++i) (ans[0] += (ans[i] ^ i)) %= 1000000007;
  printf("%d\n", ans[0]);
}
