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

#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  int k;
  cin >> k;
  int ans = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= k; l++) {
        ans += gcd(gcd(i, j), l);
      }
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int solve_kouyakusu(int a, int b, int c) {
  int max_yakusu = 1;
  int max_n = max(a, max(b, c));
  for (int i = 1; i <= max_n; i++) {
    if (a % i == 0 && b % i == 0 && c % i == 0)
      max_yakusu = i;
  }
  return max_yakusu;
}

int main() {
  int k;
  cin >> k;
  int ans = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= k; l++) {
        ans += solve_kouyakusu(i, j, l);
      }
    }
  }
  cout << ans << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <cmath>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i < n + 1; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
int main() {
  int p;
  cin >> p;
  int i, j, k, sum1 = 0;
  for (i = 1; i < p + 1; i++) {
    for (j = 1; j < p + 1; j++) {
      int temp1, more, less;
      if (i < j) {
        more = j;
        less = i;
      } else {
        more = i;
        less = j;
      }
      while (more % less != 0) {
        temp1 = less;
        less = more % less;
        more = temp1;
      }
      for (k = 1; k < p + 1; k++) {
        int temp2, more1, less1;
        if (less < k) {
          more1 = k;
          less1 = less;
        } else {
          more1 = less;
          less1 = k;
        }
        while (more1 % less1 != 0) {
          temp2 = less1;
          less1 = more1 % less1;
          more1 = temp2;
        }
        sum1 += less1;
      }
    }
  }
  cout << sum1 << endl;
}


Error: -8

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i < n + 1; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
int main() {
  int p;
  cin >> p;
  int i, j, k, sum1 = 0;
  for (i = 0; i < p; i++) {
    for (j = 0; j < p; j++) {
      int temp2, temp;
      if (i < j) {
        temp = i;
        i = j;
        j = temp;
      }
      while (i % j != 0) {
        temp2 = j;
        j = i % j;
      }
      for (k = 0; k < p; k++) {
        int temp3, temp4;
        if (j < k) {
          temp3 = j;
          j = k;
          k = temp3;
        }
        while (j % k != 0) {
          temp4 = k;
          k = j % k;
        }
        sum1 += k;
      }
    }
  }
  cout << sum1 << endl;
}
Problem p02713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll hcf(ll a, ll b) {
  if (a == 0)
    return b;
  else
    return hcf(b % a, a);
}
int main() {
  ll n, i, j, k, val = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) {
        val += hcf(k, hcf(i, j));
      }
    }
  }
  cout << val;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll hcf(ll a, ll b, ll c) {
  ll st, hcf;
  st = a < b ? (a < c ? a : c) : (b < c ? b : c);
  for (hcf = st; hcf >= 1; hcf--) {
    if (a % hcf == 0 && b % hcf == 0 && c % hcf == 0)
      break;
  }
  return hcf;
}
int main() {
  ll n, i, j, k, val = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) {
        val += hcf(i, j, k);
      }
    }
  }
  cout << val;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

/*.....Bismillahir Rahmanir Rahim.....*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define pii pair<int, int>
using namespace std;

int gcd(int a, int b) { return ((b == 0) ? a : gcd(b, a % b)); }

void solve() {
  int n, s = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        int p = gcd(i, j);
        s += gcd(p, k);
      }
    }
  }
  cout << s << endl;
}

signed main() {
  solve();
  return 0;
}


Error: -11

Fixed submission:

/*.....Bismillahir Rahmanir Rahim.....*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define pii pair<int, int>
using namespace std;
int md = 1000000007;

int pow(int p) { return (p == 0) ? 1 : (2 * pow(p - 1)) % md; }

inline void solve() {
  int n, m, cnt = 0;
  cin >> n >> m;
  int r[n + 1], c[m + 1];
  for (int i = 1; i <= n; i++)
    cin >> r[i];
  for (int i = 1; i <= m; i++)
    cin >> c[i];
  bool valid = true;
  for (int i = 1; i <= n; i++) {
    if (r[i] < m && c[r[i] + 1] >= i) {
      valid = false;
      break;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (c[i] < n && r[c[i] + 1] >= i) {
      valid = false;
      break;
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = r[i] + 2; j <= m; j++) {
      if (c[j] + 2 <= i)
        cnt++;
    }
  }
  if (!valid)
    cout << 0 << endl;
  else
    cout << ((int)pow(cnt) % md) << endl;
}

signed main() {
  solve();
  return 0;
}
Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  int k;
  cin >> k;
  long long sum = 0;
  int a = 1;
  for (int i = 0; i < k; i++) {
    int b = 1;
    for (int j = 0; j < k; j++) {
      int c = 1;
      for (int l = 0; l < k; l++) {
        sum += gcd(a, gcd(b, c));
        c++;
      }
      b++;
    }
    a++;
  }
  cout << sum;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int gcd(int a, int b) {
  int t = max(a, b);
  b = min(a, b);
  a = t;
  if (b == 0)
    return a;
  gcd(b, a % b);
}

int main() {
  int k;
  cin >> k;
  int sum = 0;
  int a = 1, b, c;
  while (a <= k) {
    b = 1;
    while (b <= k) {
      c = 1;
      while (c <= k) {
        sum += gcd(a, gcd(b, c));
        c++;
      }
      b++;
    }
    a++;
  }
  cout << sum;
  return 0;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int, int>, int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

// 最大公約数
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}

// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

// コンビネーションを計算する関数
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
int main() {
  cout << fixed << setprecision(15);
  ll N, K;
  cin >> N >> K;

  vector<ll> F(K + 1, 0);

  for (ll i = K; i >= 1; i--) {
    F[i] = modpow(floor(K / i), N);
    ll now = i;
    ll counter = 2;
    while (now * counter <= K) {
      F[i] -= F[now * counter];
      F[i] = (F[i] + MOD) % MOD;
      counter++;
    }
  }

  ll ans = 0;
  for (ll i = 1; i <= K; i++) {
    ans += F[i] * i;
    ans = ans % MOD;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int, int>, int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

// 最大公約数
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}

// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

// コンビネーションを計算する関数
ll modpow(ll N, ll k) {
  ll res = 1;
  for (ll i = 0; i < k; ++i) {
    res *= N;
    res = res % MOD;
  }
  return res;
}
int main() {
  cout << fixed << setprecision(15);
  ll N, K;
  cin >> N >> K;

  vector<ll> F(N + 1, 0);

  for (ll i = K; i >= 1; i--) {
    F[i] = modpow(floor(K / i), N);
    ll now = i;
    ll counter = 2;
    while (now * counter <= K) {
      F[i] -= F[now * counter];
      F[i] = (F[i] + MOD) % MOD;
      counter++;
    }
  }

  ll ans = 0;
  for (ll i = 1; i <= K; i++) {
    ans += F[i] * i;
    ans = ans % MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02715 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % mod;
  }
  return n * rep_jijo(n, x - 1) % mod;
}
ll com(ll n, ll r) {
  ll x = 1, y = 1;
  ll tmp = n;
  while (tmp >= n - r + 1) {
    x = x * tmp % mod;
    tmp--;
  }
  while (r > 0) {
    y = y * r % mod;
    r--;
  }
  return x * rep_jijo(y, mod - 2) % mod;
}

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

  d[K - 1] = 1;
  for (ll i = K; i > 0; i--) {
    ll sum = 0;
    for (ll j = 2 * i; j <= K; j += i) {
      sum += d[j - 1];
    }
    ll z = rep_jijo(K / i, N);
    d[i - 1] = z - sum;
  }
  ll ans = 0;
  rep(i, K) {
    ans += d[i] * (i + 1);
    ans %= mod;
  }

  cout << ans % mod << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % mod;
  }
  return n * rep_jijo(n, x - 1) % mod;
}
ll com(ll n, ll r) {
  ll x = 1, y = 1;
  ll tmp = n;
  while (tmp >= n - r + 1) {
    x = x * tmp % mod;
    tmp--;
  }
  while (r > 0) {
    y = y * r % mod;
    r--;
  }
  return x * rep_jijo(y, mod - 2) % mod;
}

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

  d[K - 1] = 1;
  for (ll i = K; i > 0; i--) {
    ll sum = 0;
    for (ll j = 2 * i; j <= K; j += i) {
      sum += d[j - 1];
    }
    ll z = 1;
    ll tmp = N;
    ll x = K / i;
    while (tmp > 0) {
      z *= x;
      z %= mod;
      tmp--;
    }

    d[i - 1] = z - sum;
  }
  ll ans = 0;
  rep(i, K) {
    ans += d[i] * (i + 1);
    ans %= mod;
  }

  cout << ans % mod << endl;
  return 0;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#pragma gcc optimize("O2")
#pragma gcc optimize("unroll-loops")

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define el '\\n'

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int N = 1e5 + 10;
const ll MOD = 1e9 + 7;

int n, k;
ll cnt[N];
vector<int> fac[N];

ll fpow(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1) {
      ret = ret * a % MOD;
    }
    a = a * a % MOD;
    b >>= 1;
  }
  return ret;
}

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

  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    for (int j = i + i; j <= k; j += i) {
      fac[j].pb(i);
    }
  }
  ll ans = 0;
  for (int i = k; i >= 1; i--) {
    ll bag = k / i;
    ll temp = fpow(bag, n);
    cnt[i] = (cnt[i] + temp + MOD) % MOD;
    ans = (ans + cnt[i] * i) % MOD;

    for (auto x : fac[i]) {
      cnt[x] = (cnt[x] - cnt[i] + MOD) % MOD;
    }
  }
  cout << ans << el;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m = 1000000007;

ll power(ll k, ll n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return k;
  ll a = 0;
  a = power(k, n / 2);
  a = ((a % m) * (a % m)) % m;
  if (n % 2 == 1)
    a = ((a % m) * (k % m));
  return a;
}

int main() {
  ll n, k, i, j, z, ans = 0;
  cin >> n >> k;
  ll dp[n + 1];
  for (i = k; i >= 1; i--) {
    dp[i] = power(k / i, n);
    // dp[i]=dp[i]%m;
    for (j = i * 2; j <= k; j += i) {
      dp[i] = (dp[i] - dp[j]);
    }
  }
  //  for(i=1;i<=k;i++)
  //        cout<<dp[i]<<" ";cout<<endl;
  for (i = 1; i <= k; i++) {
    ans = (ans + ((dp[i] * i)) % m) % m;
  }
  cout << ans << endl;
}
Problem p02715 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

long long power(long long x, long long y, long long p) {
  long long res = 1;

  x = x % p;

  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;

    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

void solve() {
  ll n, k;
  cin >> n >> k;
  ll i, j;
  ll cnt[k + 1];
  clr(cnt);
  for (i = 1; i <= k; i++) {
    cnt[i] = k / i;
  }
  ll ans[k + 1];
  clr(ans);
  for (i = k; i >= 1; i--) {
    ll tans = power(cnt[i], n, mod);
    for (j = 2 * i; j <= k; j += i) {
      tans -= ans[j];
      tans %= mod;
      tans += mod;
      tans %= mod;
    }
    ans[i] = tans;
  }
  ll nos2 = 0;
  ll res = 0;
  for (i = 1; i <= k; i++) {
    ll tans = ans[i] * i;
    res += tans;
    res %= mod;
  }
  res %= mod;
  res += mod;
  res %= mod;

  cout << res << "\\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  cout << setprecision(20);

  ll t = 1;

  // cin>>t;

  while (t--) {
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long LL;
inline LL read() {
  LL kk = 0, f = 1;
  char cc = getchar();
  while (cc < '0' || cc > '9') {
    if (cc == '-')
      f = -1;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') {
    kk = (kk << 1) + (kk << 3) + cc - '0';
    cc = getchar();
  }
  return kk * f;
}
const LL mod = 1e9 + 7;
LL cun[2000222];
LL qc(LL a, LL b) {
  LL kk = 0;
  while (b) {
    if (b & 1)
      kk = (kk + a) % mod;
    b >>= 1;
    a = (a + a) % mod;
  }
  return kk;
}
LL qp(LL a, LL b) {
  LL kk = 1;
  while (b) {
    if (b & 1)
      kk = qc(kk, a);
    b >>= 1;
    a = qc(a, a);
  }
  return kk;
}
LL n, k;
void dfs(LL x) {
  if (cun[x])
    return;
  cun[x] = qp(k / x, n);
  for (int i = 2; i <= k / x; ++i) {
    dfs(i * x);
    cun[x] -= cun[i * x];
  }
}
int main() {
  scanf("%lld%lld", &n, &k);
  LL asd = 0;
  for (LL i = 1; i <= k; ++i) {
    dfs(i);
    asd = (asd + (qc(i, cun[i])) + mod) % mod;
  }
  printf("%lld\\n", (asd + mod) % mod);
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

long long modpow(long long a, long long n, long long mod) {
  long long 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;
  ll ans = 0;
  vector<ll> gcd(k + 1);
  for (ll i = k; i >= 1; i--) {
    gcd[i] = modpow(k / i, n, 1000000007);
    for (ll j = 2; j * i <= k; j++) {
      gcd[i] -= gcd[j * i];
      gcd[i] %= 1000000007;
    }
    ans += gcd[i] * i;
    ans %= 1000000007;
  }
  if (ans < 0) {
    ans += 1000000007;
  }
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n;
  string s;
  ll ans = 0;
  cin >> n >> s;
  ll cnt_r = 0;
  ll cnt_g = 0;
  ll cnt_b = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') {
      cnt_r++;
    } else if (s[i] == 'G') {
      cnt_g++;
    } else {
      cnt_b++;
    }
  }
  ans = cnt_b * cnt_g * cnt_r;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] != s[j] && s[j] != s[2 * j - i] && s[2 * j - i] != s[i] &&
          2 * j - i < n) {
        ans--;
      }
    }
  }
  cout << ans;
}
Problem p02715 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rp(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
#define MOD 1000000007
ll dp[100005];
ll RS(ll x, ll y, ll mod) {
  if (y == 0)
    return 1;
  else if (y & 1)
    return x * RS(x, y - 1, mod) % mod;
  else {
    ll p = RS(x, y / 2, mod);
    return p * p % mod;
  }
}
int main() {
  ll n, k;
  cin >> n >> k;
  dp[1] = 1;
  dp[2] = RS(2, n, MOD) - 1;
  for (ll i = 3; i <= k; i++) {
    dp[i] = RS(i, n, MOD);
    for (ll j = 2; j <= sqrt(i); j++) {
      dp[i] -= dp[i / j];
      while (dp[i] < 0)
        dp[i] += MOD;
    }
    for (ll j = 1; j <= i / ((int)sqrt(i) / 1 + 1); j++) {
      dp[i] -= dp[j] * (i / j - i / (j + 1));
      while (dp[i] < 0)
        dp[i] += MOD;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= k; i++) {
    ans += dp[k / i] * i;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rp(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
#define MOD 1000000007
ll dp[100005];
ll RS(ll x, ll y, ll mod) {
  if (y == 0)
    return 1;
  else if (y & 1)
    return x * RS(x, y - 1, mod) % mod;
  else {
    ll p = RS(x, y / 2, mod);
    return p * p % mod;
  }
}
int main() {
  ll n, k;
  cin >> n >> k;
  dp[1] = 1;
  dp[2] = RS(2, n, MOD) - 1;
  for (ll i = 3; i <= k; i++) {
    dp[i] = RS(i, n, MOD);
    for (int j = 2; j <= i; j++) {
      dp[i] -= dp[i / j];
      if (dp[i] < 0)
        dp[i] += MOD;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= k; i++) {
    ans += dp[k / i] * i;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p02715 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define Pii pair<int, int>
#define Pid pair<int, double>
#define Pdd pair<double, double>
#define MOD 1000000007
#define EPS 0.00000001
#define N_MAX 100000

using namespace std;

int powmod(int x, int y) {
  int ret = 1;
  while (y > 0) {
    if (y & 1)
      ret = (ret * x) % MOD;
    x = (x * x) % MOD;
    y >>= 1;
  }
  return ret % MOD;
}

int gcd(int x, int y) {
  if (x > y)
    swap(x, y);
  while (true) {
    y = y % x;
    if (y == 0)
      return x;
    swap(x, y);
  }
}

signed main() {
  int n, k;
  int ans = 0;
  cin >> n >> k;
  vector<int> a(k);
  REP(i, k) { a[i] = k / (i + 1); }
  vector<int> b(k);
  REP(i, k) {
    int idx = k - 1 - i;
    REP(j, a[idx] - 1) {
      b[idx] = (b[idx] - b[(j + 2) * (idx + 1) - 1] + MOD) % MOD;
    }
    b[idx] = (b[idx] + powmod(a[idx], n)) % MOD;
  }
  REP(i, k) {
    // cout << b[i] << "\\n";
    ans = (ans + b[i] * (i + 1)) % MOD;
  }
  cout << ans << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define Pii pair<int, int>
#define Pid pair<int, double>
#define Pdd pair<double, double>
#define MOD 1000000007
#define EPS 0.00000001
#define N_MAX 100000

using namespace std;

int powmod(int x, int y) {
  int ret = 1;
  REP(_, y) ret = (ret * x) % MOD;
  return ret;
}

int gcd(int x, int y) {
  if (x > y)
    swap(x, y);
  while (true) {
    y = y % x;
    if (y == 0)
      return x;
    swap(x, y);
  }
}

signed main() {
  int n, k;
  int ans = 0;
  cin >> n >> k;
  vector<int> a(k);
  REP(i, k) { a[i] = k / (i + 1); }
  vector<int> b(k);
  REP(i, k) {
    int idx = k - 1 - i;
    REP(j, a[idx] - 1) {
      b[idx] = (b[idx] - b[(j + 2) * (idx + 1) - 1] + MOD) % MOD;
    }
    b[idx] = (b[idx] + powmod(a[idx], n)) % MOD;
  }
  REP(i, k) {
    // cout << b[i] << "\\n";
    ans = (ans + b[i] * (i + 1)) % MOD;
  }
  cout << ans << "\\n";
  return 0;
}