#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, N = 2e6 + 10;
long long dp[N], P[N];
long long Pow(long long n, long long i) {
  if (i == 0) return 1;
  long long x = Pow(n, i / 2);
  return (((x * x) % MOD) * (i % 2 == 1 ? n : 1)) % MOD;
}
int32_t main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i <= k; i++) P[i] = Pow(i, n);
  long long ans = 0, sum = 0;
  for (long long i = 1; i <= k; i++) {
    dp[i] += P[i] - P[i - 1];
    dp[i] = ((dp[i] % MOD) + MOD) % MOD;
    sum += dp[i];
    sum %= MOD;
    ans += (sum ^ i);
    ans %= MOD;
    for (long long x = 2 * i; x <= k; x += i) {
      dp[x] -= dp[i];
      dp[x] = ((dp[x] % MOD) + MOD) % MOD;
    }
  }
  cout << ans << "\n";
}
