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

/************************************/
/* NoobM							*/
/* File Name : atjp.cpp				*/
/* Date : 27.06.2020 19:24:07 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b) for (int i = 0; i < int(b); i++)
#define vi(n, a)                                                               \\
  vector<int> a(n);                                                            \\
  rr(i, n) cin >> a[i]
#define pvec(a)                                                                \\
  rr(i, a.size()) cout << a[i] << " ";                                         \\
  cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector<int>

using namespace std;

vector<long long> divisors(10000001, 0);

void sieve(int N) {
  for (int p = 1; p <= N; p++) {
    for (int i = p; i <= N; i += p)
      divisors[i]++;
  }
}

void solve() {
  int n;
  cin >> n;

  sieve(n);

  ll counter = 0;

  for (int i = 1; i <= n; i++) {
    counter += (i * divisors[i]);
  }

  cout << counter << endl;
}

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

  int t = 1;
  // cin >> t;

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


Error: TLE

Fixed submission:

/************************************/
/* NoobM							*/
/* File Name : atjp.cpp				*/
/* Date : 27.06.2020 19:24:07 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b) for (int i = 0; i < int(b); i++)
#define vi(n, a)                                                               \\
  vector<int> a(n);                                                            \\
  rr(i, n) cin >> a[i]
#define pvec(a)                                                                \\
  rr(i, a.size()) cout << a[i] << " ";                                         \\
  cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector<int>

using namespace std;

int countDivisors(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}

void solve() {
  int n;
  cin >> n;

  ll counter = 0;

  for (int i = 1; i <= n; i++) {
    counter = counter + ((ll)i * (ll)countDivisors(i));
  }

  cout << counter << endl;
}

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

  int t = 1;
  // cin >> t;

  while (t--) {
    solve();
  }
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define PI 2 * acos(0)
#define INF 1e17
#define mx 998244353
using namespace std;
ll int mod(ll int a, ll int b) {
  ll int m = a % b;
  if (m < 0)
    m = (b < 0) ? (m - b) : (m + b);
  return m;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll int n, x, y, i, j, sum;
  cin >> n;
  sum = 0;
  for (x = 1; x <= n; x++) {
    y = n / x;
    sum += ((y * (y + 1)) / 2) * x;
  }
  cout << sum;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define PI 2 * acos(0)
#define INF 1e17
#define mx 10000001
using namespace std;
ll int dp[10000001];
ll int divisor(ll int n) {
  ll int i, div = 1;
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ll int count = 0;
      while (n % i == 0) {
        n /= i;
        count++;
      }
      div *= (count + 1);
    }
  }
  if (n > 1) {
    div *= 2;
  }
  return div;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  memset(dp, -1, sizeof(dp));
  for (ll i = 1; i <= 1000000; i++)
    dp[i] = i * divisor(i);
  // for(ll i=1000001;i<mx;i++) dp[i]=i*divisor(i);
  ll int i, j, n, sum;
  cin >> n;
  sum = 0;
  for (i = 1; i <= n; i++) {
    if (dp[i] != -1)
      sum += dp[i];
    else
      sum += i * divisor(i);
  }
  cout << sum;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long

int main() {

  int N;
  cin >> N;
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ll c = N / i;
    ans += c * (c + 1) / 2 * i;
  }
  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

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

#define ll long long

int main() {

  int N;
  cin >> N;
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (i % j == 0) {
        ans += i;
      }
    }
  }
  cout << ans;

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

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 1001001001;
const int MOD = 1000000007;

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

  int n;
  cin >> n;
  ll ans = 0;
  rep(i, 1, n + 1) {
    int cnt = n / i;
    ll res = (ll)cnt * (cnt + 1) / 2 * i;
    ans += res;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 1001001001;
const int MOD = 1000000007;

const int NMAX = 10000005;
ll f[NMAX];
ll prime(int x) {
  ll ans = 1;
  for (int i = 2; (ll)i * i <= x; i++) {
    int cnt = 1;
    while (x % i == 0) {
      cnt++;
      x /= i;
    }
    ans *= cnt;
  }
  // cout << x << endl;
  if (x != 1)
    ans *= 2;
  return ans;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  int n;
  cin >> n;
  rep(i, 1, n + 1) {
    f[i] = prime(i);
    // cout << f[i] << endl;
  }
  ll ans = 0;
  rep(i, 1, n + 1) {
    // cout << f[i] << endl;
    ans += (ll)i * f[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main(void) {
  int N;
  cin >> N;

  vector<int> factors(N + 1, 0);
  factors[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (factors[i] == 0) {
      for (int j = i; j <= N; j += i) {
        factors[j] = i;
      }
    }
  }

  map<int, int> table;
  unsigned long long total = 1;

  for (int i = 2; i <= N; i++) {
    table.clear();
    int j = i;
    while (true) {
      int f = factors[j];
      if (table.find(f) == table.end()) {
        table[f] = 1;
      } else {
        table[f]++;
      }
      if (f == j) {
        break;
      }
      j /= f;
    }
    unsigned long long count = 1;
    for (auto p = table.begin(); p != table.end(); p++) {
      count *= (p->second + 1);
    }
    total += count * i;
  }

  cout << total << endl;
  return 0;
}


Error: MLE

Fixed submission:

#include <iostream>
#include <map>
#include <vector>

using namespace std;

vector<map<int, int>> factorize_cache;
int hits = 0;

const map<int, int> *factorize(int n, int i = 2) {
  auto factors = &factorize_cache[n];
  if (factors->size() == 0) {
    while (1) {
      if (n % i == 0) {
        factorize_cache[n] = *factorize(n / i, i);
        factors = &factorize_cache[n];
        hits += 1;
        if (factors->find(i) == factors->end()) {
          (*factors)[i] = 1;
        } else {
          (*factors)[i]++;
        }
        break;
      }
      i++;
      if (i * i > n) {
        (*factors)[n] = 1;
        break;
      }
    }
  }
  return factors;
}

int main(void) {
  int N;
  cin >> N;

  vector<int> factors(N + 1, 0);
  factors[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (factors[i] == 0) {
      for (int j = i; j <= N; j += i) {
        factors[j] = i;
      }
    }
  }
  vector<map<int, int> *> factor_table(N + 1, nullptr);

  for (int i = 1; i <= N; i++) {
    int f = factors[i];
    if (f == i) {
      auto t = factor_table[i] = new map<int, int>();
      (*t)[i] = 1;
    } else {
      auto t = factor_table[i] = new map<int, int>(*factor_table[i / f]);
      if (t->find(f) == t->end()) {
        (*t)[f] = 1;
      } else {
        (*t)[f]++;
      }
    }
  }

  unsigned long long total = 1;
  for (int i = 2; i <= N; i++) {
    unsigned long long count = 1;
    auto t = factor_table[i];
    for (auto p = t->begin(); p != t->end(); p++) {
      count *= (p->second + 1);
    }
    //		cout << i << "," << count << endl;
    total += count * i;
  }

  cout << total << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
// #include <string>
// #include <algorithm>
// #include <math.h>
// #include <queue>
// #include <stack>
// #include <iomanip>

// sometimes used
// #include <set>
// #include <map>
// #include <numeric>
// #include <list>
// #include <deque>
// #include <unordered_map>

typedef long long LL;
// typedef long double LD;
using namespace std;

// #define MOD 1000000007
// #define MAX 10000100
// #define NIL -1

int main() {
  LL n;
  LL ans = 0;
  cin >> n;

  vector<LL> num_divisor(n + 1, 0);

  for (LL i = 1; i <= n; i++) {
    for (LL j = i; j <= n; j = j + i) {
      num_divisor[j]++;
    }
  }

  for (LL i = 1; i <= n; i++) {
    ans = ans + i * num_divisor[i];
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
// #include <string>
// #include <algorithm>
// #include <math.h>
// #include <queue>
// #include <stack>
// #include <iomanip>

// sometimes used
// #include <set>
// #include <map>
// #include <numeric>
// #include <list>
// #include <deque>
// #include <unordered_map>

typedef long long LL;
// typedef long double LD;
using namespace std;

// #define MOD 1000000007
#define MAX 10000100
// #define NIL -1

vector<bool> is_prime(MAX + 1, true);

void eratos(LL num) {
  for (LL i = 2; i * i <= num; i++) {
    if (is_prime[i] == true) {
      // cout << i << endl;
      LL j = 2 * i;
      while (j <= num) {
        is_prime[j] = false;
        j = j + i;
      }
    }
  }
}

LL divisor_gen(LL n) {
  LL out = 1;
  for (LL i = 2; i * i <= n; i++) {
    if (n % i != 0) {
      continue;
    }
    LL num = 0;
    while (n % i == 0) {
      num++;
      n /= i;
    }
    out = out * (num + 1);
  }
  if (n != 1) {
    out *= 2;
  }

  return out;
}

int main() {
  LL n;
  LL ans = 1;
  cin >> n;

  is_prime[0] = false;
  is_prime[1] = false;

  eratos(n);

  LL tmp = 0;
  for (LL i = 2; i <= n; i++) {
    if (is_prime[i] == false) {
      tmp = divisor_gen(i);
      // cout << tmp << endl;
      ans = ans + i * tmp;
    } else {
      ans = ans + i * 2;
    }
    // cout << i << " " << ans << " " << tmp << endl;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define ll long long
// #define pw (ll)pow
#define MAX 10000001
#define MOD (ll)1e9 + 7
using namespace std;

vector<ll> dv(MAX, 0);

void nd(ll n) {
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i)
      dv[j]++;
  }
}

int main() {
  ll n;
  cin >> n;
  nd(n);
  ll c = 0;
  for (ll i = 1; i <= n; i++) {
    c += i * dv[i];
  }
  cout << c << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
// #define pw (ll)pow
#define MAX 10000001
#define MOD (ll)1e9 + 7
using namespace std;

bool prime[MAX];
vector<ll> prs;

void sieve() {
  prime[1] = true;
  ll x = sqrt(MAX);
  for (ll i = 2; i <= x; i++) {
    for (ll j = i * i; j < MAX; j += i)
      prime[j] = true;
  }
  for (ll i = 1; i < MAX; i++) {
    if (!prime[i])
      prs.push_back(i);
  }
}

ll nd(ll n) {
  if (n == 1)
    return 1;
  if (!prime[n])
    return 2;
  ll q = sqrt(n);
  if (q * q == n && !prime[q])
    return 3;
  vector<ll> s;
  for (auto p : prs) {
    ll c = 0;
    while (n % p == 0) {
      n /= p;
      c++;
    }
    s.push_back(c);
    if (!prime[n]) {
      s.push_back(1);
      break;
    }
    if (n < 2)
      break;
  }
  ll x = 1;
  for (auto z : s) {
    x *= (z + 1);
  }
  return x;
}

int main() {
  sieve();
  ll n;
  cin >> n;
  ll c = 0;
  for (ll i = 1; i <= n; i++) {
    c += i * nd(i);
  }
  cout << c << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
求 i*f(i)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 10000007

ll sum[maxn], ans, n;

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j += i) {
      sum[j]++;
    }
  for (int i = 1; i <= n; i++)
    ans += i * sum[i];
  cout << ans << '\\n';
}


Error: TLE

Fixed submission:

/*
求 i*f(i)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 10000007

ll prime[10000005], m;
bool vis[maxn];
void init() {
  for (int i = 2; i < maxn; i++) {
    if (!vis[i])
      prime[++m] = i;
    for (int j = 1; j <= m; j++) {
      if (prime[j] * i >= maxn)
        break;
      vis[prime[j] * i] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
}

ll n, ans;

ll mm, p[10000006], c[10000005];
inline ll divide(int x) {
  mm = 0;
  for (register int i = 1; prime[i] * prime[i] <= x; i++)
    if (x % prime[i] == 0) {
      p[++mm] = prime[i];
      c[mm] = 0;
      while (x % prime[i] == 0)
        x /= prime[i], c[mm]++;
    }
  if (x > 1)
    ++mm, p[mm] = x, c[mm] = 1;

  ll res = 1;
  for (register int i = 1; i <= mm; i++) {
    res *= c[i] + 1;
  }
  return res;
}

int main() {
  init();
  cin >> n;
  for (register int i = 1; i <= n; i++)
    ans += divide(i) * i;
  cout << ans << '\\n';
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < n; i++)
#define cint(a)                                                                \\
  int a;                                                                       \\
  cin >> a;
#define cstr(str)                                                              \\
  string str;                                                                  \\
  cin >> str;
#define vv(Type, n, m, d) vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;

int main(void) {

  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;

  ll ans = 0;
  ll m; // kousuu
  ll a; // 最後の項
  for (ll i = 1; i <= n; i++) {
    m = n / i;
    ans += m * (m + 1) * i / 2;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define ll long long int

#define rep(i, n) for (int i = 0; i < n; i++)
const ll mod = 1e9 + 7;

// 素因数分解
template <typename T> map<T, T> prime_factor(T n) {
  map<T, T> ret;
  for (T i = 2; i * i <= n; i++) {
    T tmp = 0;
    while (n % i == 0) {
      tmp++;
      n /= i;
    }
    ret[i] = tmp;
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

/*  divisor_num(n)
    入力：整数 n
    出力：nの約数の個数
    計算量：O(√n)
*/
template <typename T> T divisor_num(T N) {
  map<T, T> pf = prime_factor(N);
  T ret = 1;
  for (auto p : pf) {
    ret *= (p.second + 1);
  }
  return ret;
}

long long N;

int main(void) {

  ios::sync_with_stdio(false);
  cin.tie(0);

  ll ans = 0;
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    ans += i * divisor_num(i);

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;

int main() {
  ll n;
  cin >> n;
  vec cnt(n + 1);
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j * i <= n; j++) {
      cnt[j * i]++;
    }
    ans += i * cnt[i];
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) {
    res[n]++;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ll tmp = 1;
    map<ll, ll> p = prime_factor(i);
    for (auto q : p) {
      tmp *= q.second + 1;
    }
    ans += i * tmp;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

typedef long long LL;
typedef unsigned long long LONG;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
const LL INT32 = (LL(MAXINT) + 1) * 2;
using namespace std;
typedef pair<int, int> PII;
#define ft fisrt
#define sd second
#define eb emplace_back
#define END '\\n'
#define debug(x) cerr << #x << ": " << (x) << '\\n'

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  LL ans = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    LL l = i, r = (n / i) * i;
    ans += (l + r) * (r / l) / 2;
    // debug(ans);
  }
  cout << ans << endl;
  // system("pause");
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

typedef long long LL;
typedef unsigned long long LONG;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
const LL INT32 = (LL(MAXINT) + 1) * 2;
using namespace std;
typedef pair<int, int> PII;
#define ft fisrt
#define sd second
#define eb emplace_back
#define END '\\n'
#define debug(x) cerr << #x << ": " << (x) << '\\n'

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  LL ans = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int l = i, r = (n / i) * i;
    ans += (l + r) * (r / l) / 2;
    debug(ans);
  }
  cout << ans << endl;
  // system("pause");
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  ll n;
  cin >> n;
  ll res = 0;
  vector<int> a(n + 1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  // rep(i, n + 1) cout << a[i] << ' ';
  // cout << endl;
  for (int i = 1; i <= n; i++) {
    res += (ll)a[i] * (ll)i;
  }
  cout << res << endl;
}


Error: TLE

Fixed submission:

// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  ll n;
  cin >> n;
  ll res = 0;
  for (ll i = 1; i <= n; i++) {
    ll cnt = 0;
    for (ll j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        cnt++;
        if (i / j != j)
          cnt++;
      }
    }
    res += (cnt * i);
    // cout << cnt << ' ' << i << endl;
  }
  cout << res << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    long long temp = n / i;
    sum += i * ((temp * (temp + 1)) / 2);
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

vector<pair<long, long>> factor(long n) {
  vector<pair<long, long>> f;
  for (long p = 2; p * p <= n; p++) {
    if (n % p != 0)
      continue;
    long q = 0;
    while (n % p == 0) {
      q++;
      n = n / p;
    }
    f.push_back({p, q});
  }
  // 素数の場合
  if (n != 1)
    f.push_back({n, 1});
  return f;
}

int main() {
  int n;
  cin >> n;
  long long sum = 0, tempsum = 1;
  for (int i = 1; i <= n; i++) {
    vector<pair<long, long>> temp = factor(i);
    tempsum = 1;
    for (int j = 0; j < temp.size(); j++) {
      tempsum *= temp[j].second + 1;
    }
    sum += i * tempsum;
  }
  cout << sum << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long int arr[10000001], brr[10000001];
long long int p[1000000];
void calpr(int n) {
  int i, j;
  for (i = 1; i <= n; i++) {
    // if(p[i]==0){
    for (j = i; j <= n; j += i) {
      p[j]++;
    }
  }
}
void calarr(int a) {
  int i, j, k;
  long long int x, y, z, n;
  for (i = 2; i <= a; i++) {
    n = i;
    x = 0, y = 1;
    while (n % 2 == 0) {
      n /= 2;
      x++;
    }
    y *= (x + 1);
    x = 0;
    for (j = 3; j < 10000; j += 2) {
      if (p[j] == 0) {
        while (n % j == 0) {
          n /= j;
          x++;
        }
        y *= (x + 1);
        x = 0;
      }
    }
    if (n != 1)
      y *= 2;
    arr[i] = y * i;
  }
}
int main() {
  long long int i, j, n, x = 0;
  // calpr();
  // calarr();
  /*for(i=2;i<25;i++){
      cout<<p[i];
  }
  cout<<"\\n";*/
  scanf("%lld", &n);
  calpr(n);
  // calarr(n);
  for (i = 2; i <= n; i++) {
    x += i * p[i];
  }
  x++;
  printf("%lld\\n", x);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long int arr[10000001], brr[10000001];
long long int p[1000000];
void calpr() {
  int i, j;
  for (i = 2; i < 10000; i++) {
    if (p[i] == 0) {
      for (j = 2 * i; j < 10000; j += i) {
        p[j] = 1;
      }
    }
  }
}
void calarr(int a) {
  int i, j, k;
  long long int x, y, z, n;
  for (i = 2; i <= a; i++) {
    n = i;
    x = 0, y = 1;
    while (n % 2 == 0) {
      n /= 2;
      x++;
    }
    y *= (x + 1);
    x = 0;
    for (j = 3; j < 10000; j += 2) {
      if (p[j] == 0) {
        while (n % j == 0) {
          n /= j;
          x++;
        }
        y *= (x + 1);
        x = 0;
      }
    }
    if (n != 1)
      y *= 2;
    arr[i] = y * i;
  }
}
int main() {
  long long int i, j, n, x = 0;
  calpr();
  // calarr();
  /*for(i=2;i<25;i++){
      cout<<p[i];
  }
  cout<<"\\n";*/
  scanf("%lld", &n);
  calarr(n);
  for (i = 2; i <= n; i++) {
    x += arr[i];
  }
  x++;
  printf("%lld\\n", x);
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <iostream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(void) {
  int n;
  ll m = 0;

  cin >> n;

  for (int i = 1; i <= n; i++) {
    m += (n / i) * 0.5 * (2 * i + (n / i - 1) * i);
    // cout << m << endl;
  }

  cout << m << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <iostream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int soin(int n) {
  int ans = 1;

  vector<int> x(n + 1);
  int num = n; // 素因数分解する変数num

  for (int i = 2; i <= n; i++) {
    while (num % i == 0) { // 素数で割り切れなくなるまで割っていく
      x.at(i)++;
      num /= i;
    }
  }

  for (int i = 2; i <= n; i++) {
    ans *= x.at(i) + 1;
  }

  return ans;
}

int main(void) {
  ll n;
  ll m = 0;

  cin >> n;

  for (int i = 1; i <= n; i++) {
    m += soin(i) * i;
  }

  cout << m << endl;

  return 0;
}