alexjercan/bugnet huggingface dataset:
Problem p02715 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const ll inf = 1e18;
const ll mod = 1000000007;

template <typename T> T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1)
      result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

int main() {
  ll n, k;
  cin >> n >> k;
  ll sum = 0;
  vll x(k + 1);
  for (int i = k; i >= 1; i--) {
    ll tmp = k / i;
    tmp = modpow(tmp, n, mod);
    for (int l = 2; i * l <= k; l++) {
      tmp += mod;
      tmp -= x[i * l];
      tmp %= mod;
    }
    x[i] = tmp % mod;
    sum += x[i] * i;
    sum %= mod;
  }
  cout << sum % mod << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const ll inf = 1e18;
const ll mod = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  ll sum = 0;
  vll x(k + 1);
  for (int i = k; i >= 1; i--) {
    ll tmp = k / i;
    rep(j, n - 1) {
      tmp *= k / i;
      tmp %= mod;
    }
    for (int l = 2; i * l <= k; l++) {
      tmp += mod;
      tmp -= x[i * l];
      tmp %= mod;
    }
    x[i] = tmp % mod;
    sum += x[i] * i;
    sum %= mod;
  }
  cout << sum % mod << endl;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

long long power(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b % 2) {
      ans = ans * a % mod;
    }
    a = a * a % mod;
    b /= 2;
  }
  return ans;
}

int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(k + 1, 0);
  for (long long i = k; i >= 1; i--) {
    a[i] = power(k / i, n);
    int j = 2;
    while (i * j <= k) {
      a[i] = (a[i] - a[i * j]) % mod;
      if (a[i] < 0) {
        a[i] += mod;
      }
      j++;
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= k; i++) {
    ans += a[i] * i % mod;
    ans %= mod;
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

long long power(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b % 2) {
      ans = ans * a % mod;
    }
    a = a * a % mod;
    b /= 2;
  }
  return ans;
}

int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(k + 1, 0);
  for (long long i = k; i >= 1; i--) {
    a[i] = power(k / i, n);
    int j = 2;
    while (j <= i) {
      a[i] = (a[i] - a[i * j]) % mod;
      if (a[i] < 0) {
        a[i] += mod;
      }
      j++;
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= k; i++) {
    ans += a[i] * i % mod;
    ans %= mod;
  }
  cout << ans;
  return 0;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF (1LL << 60)
#define MOD7 1000000007LL
#define PREP(i, s, x) for (ll i = (s); i < (x); i++)
#define MREP(i, s, x) for (ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll llgcd(ll a, ll b) {
  if (b == 0)
    return a;
  return llgcd(b, a % b);
}

ll llpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD7;
    a = a * a % MOD7;
    n >>= 1;
  }
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> kumi(k + 10, 0);
  for (ll p = k; p >= 1; p--) {
    if (p == 0) {
      continue;
    }
    ll a = k / p;
    ll mimi = 0;
    for (ll i = 2 * p; i <= k; i += p) {
      mimi += kumi[i];
      mimi %= MOD7;
    }
    kumi[p] = (llpow(a, n) - mimi) % MOD7;
    kumi[p] %= MOD7;
    if (kumi[p] < 0) {
      kumi[p] += MOD7;
    }
  }

  ll ans = 0;
  for (ll i = 1; i <= k; i++) {
    ans += (kumi[i] * i) % MOD7;
    ans %= MOD7;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define INF (1LL << 60)
#define MOD7 1000000007LL
#define PREP(i, s, x) for (ll i = (s); i < (x); i++)
#define MREP(i, s, x) for (ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll llgcd(ll a, ll b) {
  if (b == 0)
    return a;
  return llgcd(b, a % b);
}

ll llpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD7;
    a = a * a % MOD7;
    n >>= 1;
  }
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> kumi(k, 0);
  for (ll p = k; p >= 1; p--) {
    ll a = k / p;
    ll mimi = 0;
    for (ll i = 2 * p; i <= k; i += p) {
      mimi += kumi[i];
      mimi %= MOD7;
    }
    kumi[p] = (llpow(a, n) - mimi) % MOD7;
    kumi[p] %= MOD7;
    if (kumi[p] < 0) {
      kumi[p] += MOD7;
    }
  }

  ll ans = 0;
  for (ll i = 1; i <= k; i++) {
    ans += (kumi[i] * i) % MOD7;
    ans %= MOD7;
  }
  cout << ans << endl;
  return 0;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x, y) x = max(x, y)
#define gmin(x, y) x = min(x, y)
#define gadd(x, y) x = add(x, y)
#define gmul(x, y) x = mul(x, y)
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int MOD = 1e9 + 7;

inline int add(int x, int y) {
  ll res = x + y;
  while (res >= MOD)
    res -= MOD;
  return res;
}

inline int mul(int x, int y) { return (1LL * x * y) % MOD; }

int modpow(int x, int p) {
  int res = 1;
  while (p) {
    if (p & 1)
      gmul(res, x);
    gmul(x, x);
    p /= 2;
  }
  return res;
}

inline int invert(int x) { return modpow(x, MOD - 2); }

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<int> dp(k + 1);
  rep(i, 1, k + 1) {
    dp[i] = modpow(i, n);
    int la;
    for (int x = 2; x <= i; x = la + 1) {
      la = min(i / (i / x), i);
      gadd(dp[i], MOD - mul(la - x + 1, dp[i / x]));
    }
  }
  int ans = 0;
  rep(i, 1, k + 1) { gadd(ans, mul(i, dp[k / i])); }
  cout << ans << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x, y) x = max(x, y)
#define gmin(x, y) x = min(x, y)
#define gadd(x, y) x = add(x, y)
#define gmul(x, y) x = mul(x, y)
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int MOD = 1e9 + 7;

inline int add(int x, int y) {
  ll res = x + y;
  while (res >= MOD)
    res -= MOD;
  return res;
}

inline int mul(int x, int y) { return (1LL * x * y) % MOD; }

int modpow(int x, int p) {
  int res = 1;
  while (p) {
    if (p & 1)
      gmul(res, x);
    gmul(x, x);
    p /= 2;
  }
  return res;
}

inline int invert(int x) { return modpow(x, MOD - 2); }

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<int> dp(n + 1);
  rep(i, 1, k + 1) {
    dp[i] = modpow(i, n);
    int la;
    for (int x = 2; x <= i; x = la + 1) {
      la = min(i / (i / x), i);
      gadd(dp[i], MOD - mul(la - x + 1, dp[i / x]));
    }
  }
  int ans = 0;
  rep(i, 1, k + 1) { gadd(ans, mul(i, dp[k / i])); }
  cout << ans << '\\n';
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define pb push_back
#define mp make_pair
#define clr(v, d) memset(v, d, sizeof(v))
typedef long long ll;
typedef unsigned long long ull;
const double EPS = (1e-9);
using namespace std;
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
ll setBit0(ll num, int idx) { return num & ~(1ll << idx); }
ll flipBit(int num, int idx) { return num ^ (1 << idx); }
void GO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 100000 + 9, mod = 1000000000 + 7;
ll cnt[N], fres[N];
void go(ll n) {

  for (ll i = 1; i * i <= n; i++) {

    if (n % i == 0) {
      cnt[i]++;
      if (n / i != i)
        cnt[n / i]++;
    }
  }
}
ll power(ll b, ll p) {

  if (p == 0)
    return 1;
  if ((p & (1ll))) {
    return b % mod * power((b * b) % mod, p / 2) % mod;
  } else {
    return power((b * b) % mod, p / 2);
  }
}
int main() {
  GO();
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    go(i);
  }
  ll ans = 0;
  for (ll i = k; i >= 1; i--) {
    fres[i] = power(cnt[i], n);
    for (ll j = i * 2; j <= k; j += i) {
      fres[i] = ((fres[i] - fres[j]) + mod) % mod;
    }
    ans += (1ll * fres[i] * i) % mod;
    if (ans >= mod)
      ans -= mod;
  }
  cout << ans << "\\n";
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define pb push_back
#define mp make_pair
#define clr(v, d) memset(v, d, sizeof(v))
typedef long long ll;
typedef unsigned long long ull;
const double EPS = (1e-9);
using namespace std;
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
ll setBit0(ll num, int idx) { return num & ~(1ll << idx); }
ll flipBit(int num, int idx) { return num ^ (1 << idx); }
void GO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 100000 + 9, mod = 1000000000 + 7;
ll cnt[N], fres[N];
void go(ll n) {

  for (ll i = 1; i * i <= n; i++) {

    if (n % i == 0) {
      cnt[i]++;
      if (n / i != i)
        cnt[n / i]++;
    }
  }
}
ll power(ll b, ll p) {

  if (p == 0)
    return 1;
  if ((p & (1ll))) {
    return b % mod * power((b * b) % mod, p / 2) % mod;
  } else {
    return power((b * b) % mod, p / 2);
  }
}
int main() {

  ll n, k;
  scanf("%I64d %I64d", &n, &k);
  for (int i = 1; i <= k; i++) {
    go(i);
  }
  ll ans = 0;
  for (ll i = k; i >= 1; i--) {
    fres[i] = power(cnt[i], n);
    for (ll j = i * 2; j <= k; j += i) {
      fres[i] = ((fres[i] - fres[j]) + mod) % mod;
    }
    ans += (1ll * fres[i] * i) % mod;
    if (ans >= mod)
      ans -= mod;
  }
  printf("%I64d\\n", ans);
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
ll pow(ll a, ll b) {
  ll ans = 1;
  while (b != 0) {
    if (b % 2 == 1) {
      ans = ((ans % mod) * (a % mod)) % mod;
    }
    a = ((a % mod) * (a % mod)) % mod;
    b = b / 2;
  }
  return ans % mod;
}
int main() {
  ll n, k;
  cin >> n >> k;
  ll count[k + 1];
  memset(count, 0, sizeof(count));
  count[k] = 1;

  ll ans = k;
  for (int i = k - 1; i >= 1; i--) {
    ll rem = (ll)k / i;
    count[i] = pow(rem, n);
    for (int j = i + i; j <= k; j += i) {
      count[i] = count[i] - count[j] + mod;
      if (count[i] >= mod)
        count[i] = count[i] - mod;
    }
    ans = (ans % mod + (count[i] * i) % mod) % mod;
  }
  cout << ans % mod << endl;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
ll pow(ll a, ll b) {
  ll ans = 1;
  while (b != 0) {
    if (b & 1) {
      ans = ((ans % mod) * (a % mod)) % mod;
    }
    a = ((a % mod) * (a % mod)) % mod;
    b = b / 2;
  }
  return ans % mod;
}
int main() {
  ll n, k;
  cin >> n >> k;
  ll count[k + 1];
  memset(count, 0, sizeof(count));
  count[k] = 1;

  ll ans = k;
  for (int i = k - 1; i >= 0; i--) {
    ll rem = (ll)k / i;
    count[i] = pow(rem, n);
    for (int j = i + i; j <= k; j += i) {
      count[i] = count[i] - count[j];
    }
    ans = 1ll * (ans % mod + (count[i] * i) % mod) % mod;
  }
  return ans;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

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

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> d(K + 1);
  for (int i = K; i >= 1; i--) {
    ll tmp = modpow(K / i, N);
    for (int j = 2; j * i <= K; j++) {
      tmp = (tmp + mod - d[j * i]) % mod;
    }
    d[i] = tmp;
  }

  ll ans = 0;
  for (int i = 1; i <= K; i++) {
    ans = (ans + i * d[i]) % mod;
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> d(N + 1);
  for (int i = K; i >= 1; i--) {
    ll tmp = modpow(K / i, N);
    for (int j = 2; j * i <= K; j++) {
      tmp = (tmp + mod - d[j * i]) % mod;
    }
    d[i] = tmp;
  }

  ll ans = 0;
  for (int i = 1; i <= K; i++) {
    ans = (ans + i * d[i]) % mod;
  }
  cout << ans << endl;

  return 0;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

ll MOD = 1000000007;

ll modpow(ll a, ll n = MOD - 2) {
  ll r = 1;
  a %= MOD;
  while (n) {
    r = r * ((n % 2) ? a : 1) % MOD;
    a = a * a % MOD;
    n >>= 1;
  }

  return r;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;

  ll sum = 0;
  vector<ll> dp(100001, 0);
  for (int i = K; i >= 1; i--) {
    dp[i] = modpow(K / i, N);
    for (int j = i * 2; j <= K; j += i)
      dp[i] -= dp[j];
    sum += i * dp[i] % MOD;
  }
  cout << sum % MOD << endl;

  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

ll MOD = 1000000007;

ll modpow(ll a, ll n = MOD - 2) {
  ll r = 1;
  a %= MOD;
  while (n) {
    r = r * ((n % 2) ? a : 1) % MOD;
    a = a * a % MOD;
    n >>= 1;
  }

  return r;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;

  ll sum = 0;
  vector<ll> dp(10001, 0);
  for (int i = K; i >= 1; i--) {
    dp[i] = modpow(K / i, N);
    for (int j = i * 2; j <= K; j += i)
      dp[i] -= dp[j];
    sum += i * dp[i] % MOD;
  }
  cout << sum % MOD << endl;

  return 0;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

ll mo = 1000000007;
ll dp[101010];

ll modpow(ll a, ll n = mo - 2) {
  ll r = 1;
  a %= mo;
  while (n) {
    r = r * ((n % 2) ? a : 1) % mo;
    a = a * a % mo;
    n >>= 1;
  }

  return r;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;

  ll sum = 0;
  for (int i = K; i >= 1; i--) {
    dp[i] = modpow(K / i, N);
    for (int j = i * 2; j <= K; j += i)
      dp[i] -= dp[j];
    sum += i * dp[i] % mo;
  }
  cout << sum % mo << endl;

  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const ll MOD = 1000000007;

ll modpow(ll a, ll n = MOD - 2) {
  ll r = 1;
  a %= MOD;
  while (n) {
    r = r * ((n % 2) ? a : 1) % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return r;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;

  ll sum = 0;
  vi dp(20000, 0);
  RFOR(i, K, 1) {
    dp[i] = modpow(K / i, N);
    for (int j = i * 2; j <= K; j += i)
      dp[i] -= dp[j];
    sum += i * dp[i] % MOD;
  }

  cout << sum % MOD << endl;

  return 0;
}
Problem p02715 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
ll kpow(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans *= a;
    ans %= mod;
    a *= a;
    a %= mod;
    b >>= 1;
  }
  return ans;
}
ll dp[maxn];
int main() {
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    dp[i] = kpow(k / i, n); // 表示最小公因数为i的排列组合的数量
  }

  for (int i = k; i >= 1; i--) {
    for (int j = i * 2; j <= k; j = j + i) {
      dp[i] -= dp[j];
      dp[i] = (dp[i] + mod) % mod;
    }
  }
  ll ans = 0;
  for (int i = k; i >= 1; i--) {
    ans += (i * dp[i]);
    ans %= mod;
  }
  cout << (ans + mod) % mod << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
ll kpow(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans *= a;
    ans %= mod;
    a *= a;
    a %= mod;
    b >>= 1;
  }
  return ans;
}
ll dp[maxn];
int main() {
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    dp[i] = kpow(k / i, n); // 表示最小公因数为i的排列组合的数量
  }

  for (int i = k; i >= 1; i--) {
    for (int j = i * 2; j <= k; j + i) {
      dp[i] -= dp[j];
      dp[i] = (dp[i] + mod) % mod;
    }
  }
  ll ans = 0;
  for (int i = k; i >= 1; i--) {
    ans += (i * dp[i]);
    ans %= mod;
  }
  cout << (ans + mod) % mod << endl;
  return 0;
}