Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// Sieve of Eratosthenes
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  int n, k; cin>>n>>k;
  Sieve sieve(k);
  mint ans;
  vector<mint> d(k+1);
  for (int i = 1; i <= k; ++i) d[i] = mint(k/i).pow(n);
  for (int p : sieve.primes) {
    for (int i = p; i <= k; i += p) {
      d[i/p] -= d[i];
    }
  }
  for (int i = 1; i <= k; ++i) ans += d[i]*i;
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc:63:10: error: 'P' was not declared in this scope
   63 |   vector<P> factor(int x) {
      |          ^
a.cc:63:11: error: template argument 1 is invalid
   63 |   vector<P> factor(int x) {
      |           ^
a.cc:63:11: error: template argument 2 is invalid
a.cc: In member function 'int Sieve::factor(int)':
a.cc:66:12: error: 'P' was not declared in this scope
   66 |     vector<P> res(1, P(fl[0], 0));
      |            ^
a.cc:66:13: error: template argument 1 is invalid
   66 |     vector<P> res(1, P(fl[0], 0));
      |             ^
a.cc:66:13: error: template argument 2 is invalid
a.cc:66:33: error: expression list treated as compound expression in initializer [-fpermissive]
   66 |     vector<P> res(1, P(fl[0], 0));
      |                                 ^
a.cc:68:15: error: request for member 'back' in 'res', which is of non-class type 'int'
   68 |       if (res.back().first == p) {
      |               ^~~~
a.cc:69:13: error: request for member 'back' in 'res', which is of non-class type 'int'
   69 |         res.back().second++;
      |             ^~~~
a.cc:71:13: error: request for member 'emplace_back' in 'res', which is of non-class type 'int'
   71 |         res.emplace_back(p, 1);
      |             ^~~~~~~~~~~~