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

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

int main(void) {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ll p = n / i;
    ans += i * (1 + p) * p / 2;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

ll count(ll num) {

  vector<ll> x(num + 1);
  ll n = num;

  for (ll i = 2; i <= n; i++) {
    while (num % i == 0) {
      x.at(i)++;
      num /= i;
    }
  }
  ll ans = 1;
  for (ll i = 2; i <= n; i++) {
    ans *= x.at(i) + 1;
  }
  return ans;
}

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

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n + 1, 0);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j += i)
      v[j]++;
  }
  for (int i = 1; i <= n; i++)
    ans += i * (long long)v[i];
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
void SieveOfEratosthenes(int n, bool prime[], bool primesquare[], int a[]) {
  // Create a boolean array "prime[0..n]" and
  // initialize all entries it as true. A value
  // in prime[i] will finally be false if i is
  // Not a prime, else true.
  for (int i = 2; i <= n; i++)
    prime[i] = true;

  // Create a boolean array "primesquare[0..n*n+1]"
  // and initialize all entries it as false. A value
  // in squareprime[i] will finally be true if i is
  // square of prime, else false.
  for (int i = 0; i <= (n * n + 1); i++)
    primesquare[i] = false;

  // 1 is not a prime number
  prime[1] = false;

  for (int p = 2; p * p <= n; p++) {
    // If prime[p] is not changed, then
    // it is a prime
    if (prime[p] == true) {
      // Update all multiples of p
      for (int i = p * 2; i <= n; i += p)
        prime[i] = false;
    }
  }

  int j = 0;
  for (int p = 2; p <= n; p++) {
    if (prime[p]) {
      // Storing primes in an array
      a[j] = p;

      // Update value in primesquare[p*p],
      // if p is prime.
      primesquare[p * p] = true;
      j++;
    }
  }
}

// Function to count divisors
int countDivisors(int n) {
  // If number is 1, then it will have only 1
  // as a factor. So, total factors will be 1.
  if (n == 1)
    return 1;

  bool prime[n + 1], primesquare[n * n + 1];

  int a[n]; // for storing primes upto n

  // Calling SieveOfEratosthenes to store prime
  // factors of n and to store square of prime
  // factors of n
  SieveOfEratosthenes(n, prime, primesquare, a);

  // ans will contain total number of distinct
  // divisors
  int ans = 1;

  // Loop for counting factors of n
  for (int i = 0;; i++) {
    // a[i] is not less than cube root n
    if (a[i] * a[i] * a[i] > n)
      break;

    // Calculating power of a[i] in n.
    int cnt = 1;          // cnt is power of prime a[i] in n.
    while (n % a[i] == 0) // if a[i] is a factor of n
    {
      n = n / a[i];
      cnt = cnt + 1; // incrementing power
    }

    // Calculating the number of divisors
    // If n = a^p * b^q then total divisors of n
    // are (p+1)*(q+1)
    ans = ans * cnt;
  }

  // if a[i] is greater than cube root of n

  // First case
  if (prime[n])
    ans = ans * 2;

  // Second case
  else if (primesquare[n])
    ans = ans * 3;

  // Third case
  else if (n != 1)
    ans = ans * 4;

  return ans; // Total divisors
}

int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i * countDivisors(i);
    // cout<<f(i)<<endl;
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
      author : Nishikawa
      created: 06.08.2020 14:01:46
*/

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

ll SUM(ll n) { return n * (n + 1) / 2; }

// Xまでの正の約数の総和を数えるプログラム
int main() {
  ll X;
  cin >> X;
  // vector<int> vec(X+1,0);
  ll sum = 0;
  for (ll i = 1; i <= X; i++)
    sum += SUM(X / i) * i;
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

/*
      author : Nishikawa
      created: 06.08.2020 14:01:46
*/

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

// Xまでの正の約数の総和を数えるプログラム
int main() {
  int X;
  cin >> X;
  // vector<int> vec(X+1,0);
  ll sum = 0;
  for (int i = 1; i <= X; i++) {
    for (int j = 1; j <= i; j++) {
      if (i % j == 0)
        sum += i;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

ll divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  ll a = ret.size();
  return a;
}

bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

int main() {
  int N;
  cin >> N;
  vector<ll> tmp(N + 1, 0);
  tmp[1] = 1;
  for (ll i = 1; i <= N; i++)
    for (ll j = i; j <= N; j += i)
      tmp[j] += 1;
  ll ans = 0;
  for (int i = 1; i <= N; ++i) {
    ans += i * tmp[i];
    // cout << i << " " << tmp[i] << endl;
  }
  cout << ans - 1 << endl;
}

Error: TLE

Fixed submission:

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

ll divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  ll a = ret.size();
  return a;
}

int main() {
  int N;
  cin >> N;
  vector<ll> tmp(N + 1);
  for (int i = 1; i <= N; ++i) {
    tmp[i] = divisor(i);
  }
  ll ans = 0;
  for (int i = 1; i <= N; ++i) {
    ans = ans + (i * tmp[i]);
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define sz 10000002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define VEC(n)                                                                 \\
  ll int x;                                                                    \\
  vector<ll int> v;                                                            \\
  for (int i = 0; i < n; i++) {                                                \\
    cin >> x;                                                                  \\
    v.pb(x);                                                                   \\
  }
#define TEST()                                                                 \\
  int test;                                                                    \\
  cin >> test;                                                                 \\
  while (test--)
#define FAST()                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
using namespace std;
ll divisor[10000000];

int main() {
  FAST();
  ll int n, m, res = 0;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    for (int j = 1; (ll)j * i <= n; j++) {
      divisor[i * j]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    res += i * divisor[i];
  }
  cout << res << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define sz 10000002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define VEC(n)                                                                 \\
  ll int x;                                                                    \\
  vector<ll int> v;                                                            \\
  for (int i = 0; i < n; i++) {                                                \\
    cin >> x;                                                                  \\
    v.pb(x);                                                                   \\
  }
#define TEST()                                                                 \\
  int test;                                                                    \\
  cin >> test;                                                                 \\
  while (test--)
#define FAST()                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
using namespace std;

int main() {
  FAST();
  ll int n, m, res = 0;
  cin >> n;
  map<int, int> div;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; (ll)j * i <= n; j++) {
      int x = i * j;
      x = x % (n + 1);
      div[x]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    res += i * div[i];
  }
  cout << res << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long
#define ar array

const int mxN = 1e7;
int n, c[mxN + 1];

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

  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; (j += i) <= n;)
      ++c[j];
  ll ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += (ll)i * c[i];
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int a[9999999];
vector<int> factors(int n) {
  vector<int> f;
  for (int x = 2; x * x <= n; x++) {
    while (n % x == 0) {
      f.push_back(x);
      n /= x;
    }
  }
  if (n > 1)
    f.push_back(n);
  return f;
}
long long k = 1;
int main() {
  int n;
  long long ans = 0;
  cin >> n;
  int q = 1;
  while (n--) {
    vector<int> v = factors(q);
    for (int i = 0; i < v.size(); i++) {
      a[v[i]]++;
    }
    for (int i = 0; i < v.size(); i++) {
      if (a[v[i]] != 0) {
        int y = a[v[i]];
        k *= y + 1;
        a[v[i]] = 0;
      }
    }
    ans += (q * k);
    k = 1;
    q++;
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded



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

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define F(start, stop) for (int i = start; i < stop; i++)
#define FRev(start, stop) for (int i = start; i >= stop; i--)
#define debugVector(v)                                                         \\
  for (int i = 0; it < v.size(); i++)                                          \\
    cout << v[i] << " ";                                                       \\
  cout << endl;
#define debugArray(arr, n)                                                     \\
  for (int i = 0; i < n; i++)                                                  \\
    cout << arr[i] << " ";                                                     \\
  cout << endl;
#define MOD1 1000000007
#define MOD2 998244353

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  IOS

      ll n;
  cin >> n;
  ll div[n + 1] = {0};

  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j * i <= n; j++)
      div[i * j]++;
  }

  ll ans = 0;

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

  cout << ans << endl;
}

Error: TLE

Fixed submission:



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

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define F(start, stop) for (int i = start; i < stop; i++)
#define FRev(start, stop) for (int i = start; i >= stop; i--)
#define debugVector(v)                                                         \\
  for (int i = 0; it < v.size(); i++)                                          \\
    cout << v[i] << " ";                                                       \\
  cout << endl;
#define debugArray(arr, n)                                                     \\
  for (int i = 0; i < n; i++)                                                  \\
    cout << arr[i] << " ";                                                     \\
  cout << endl;
#define MOD1 1000000007
#define MOD2 998244353

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  IOS

      ll n;
  cin >> n;
  unsigned ll ans = 0;

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

    for (ll j = 1; j <= sqrt(i); j++) {
      if (i % j == 0) {
        if (i / j == j) {
          cnt += 1;
        } else {
          cnt += 2;
        }
      }
    }

    ans += (i * cnt);
  }

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream {
public:
  Stream() {}
  // 配列以外の入力を受け取る
  void read() {}
  template <typename First, typename... Rest>
  void read(First &first, Rest &...rest) {
    cin >> first;
    read(rest...);
  }
  template <typename T> vector<T> read_vec(size_t n) {
    vector<T> tmp(n);
    for (size_t i = 0; i < n; i++) {
      cin >> tmp[i];
    }
    return tmp;
  }
  // 配列を区切って出力する
  template <typename T> void write_vec(vector<T> &v, char divider) {
    for (size_t i = 0; i < v.size(); i++) {
      cout << v[i] << divider;
    }
  }
};

int main() {
  Stream io;

  int N;
  io.read(N);

  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ans += ((N / i) + 1) * i * (N / i) / 2;
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream {
public:
  Stream() {}
  // 配列以外の入力を受け取る
  void read() {}
  template <typename First, typename... Rest>
  void read(First &first, Rest &...rest) {
    cin >> first;
    read(rest...);
  }
  template <typename T> vector<T> read_vec(size_t n) {
    vector<T> tmp(n);
    for (size_t i = 0; i < n; i++) {
      cin >> tmp[i];
    }
    return tmp;
  }
  // 配列を区切って出力する
  template <typename T> void write_vec(vector<T> &v, char divider) {
    for (size_t i = 0; i < v.size(); i++) {
      cout << v[i] << divider;
    }
  }
};

vector<ll> m(10000000 + 1, 0);

ll prime_factor(ll n) {
  ll x = 1;
  for (ll i = 2; i * i <= n; i++) {
    ll k = 1;
    while (n % i == 0)
      n /= i, k++;
    if (k > 0)
      x *= k;
  }
  if (n > 1)
    x *= 2;
  return x;
}

int main() {
  Stream io;

  ll N;
  io.read(N);
  ll ans = 1;
  for (ll i = 2; i <= N; i++) {
    ll f = 1;
    if (m[i]) {
      f = m[i];
    } else {
      f = prime_factor(i);
      m[i] = f;
    }
    ans += i * f;
  }
  cout << ans;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define ll long long
int main() {
  ll n;
  cin >> n;
  ll a[n + 1];
  for (ll i = 0; i <= n; i++) {
    a[i] = i;
  }
  ll facnt[n + 1] = {0};
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      facnt[j]++;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += i * facnt[i];
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define ll long long
ll prod = 1;
void factorize(ll n) {
  ll cnt;
  for (ll i = 2; i * i <= n; ++i) {
    cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    prod *= (cnt + 1);
  }
  if (n != 1) {
    prod *= 2;
  }
}
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    prod = 1;
    factorize(i);
    ans += prod * i;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

// prepared by dumb
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define dl double
#define llu unsigned long long int
#define scll(x) scanf("%lld", &x)
#define scdl(x) scanf("%lf", &x)
#define scull(x) scanf("%llu", &x)
#define scch(x) scanf(" %c", &x)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define ppb() pop_back()
#define ppf() pop_front()
#define Pi acos(-1.0)
#define INF 1000000000000000000
#define mod 1000000007
#define ff first
#define ss second
#define mpr make_pair
#define debug(x) cout << x << '\\n';
// sin((x*pi)/180.0)[x in degree]
// sin(x)[x in radian]
// asin(x)[radian]
//(asin(x)*180)/pi[degree]
// or(|)//and(&)//xor(^)//not(~)
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll a, b, c, d, e, f = 0, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
                    y, z;
  ll cnt = 0, ans = 0, l1, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
  ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
  string str, str1, str2;

  scll(n);
  vector<ll> coun(n + 1, 0);
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j += i)
      coun[j]++;
  }

  for (i = 1; i <= n; i++)
    ans += i * coun[i];
  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

// prepared by dumb
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define dl double
#define llu unsigned long long int
#define scll(x) scanf("%lld", &x)
#define scdl(x) scanf("%lf", &x)
#define scull(x) scanf("%llu", &x)
#define scch(x) scanf(" %c", &x)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define ppb() pop_back()
#define ppf() pop_front()
#define Pi acos(-1.0)
#define INF 1000000000000000000
#define mod 1000000007
#define ff first
#define ss second
#define mpr make_pair
#define debug(x) cout << x << '\\n';
// sin((x*pi)/180.0)[x in degree]
// sin(x)[x in radian]
// asin(x)[radian]
//(asin(x)*180)/pi[degree]
// or(|)//and(&)//xor(^)//not(~)
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll a, b, c, d, e, f = 0, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
                    y, z;
  ll cnt = 0, ans = 0, l1, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
  ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
  string str, str1, str2;

  scll(n);
  unordered_map<ll, ll> coun;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j += i)
      coun[j]++;
  }

  for (i = 1; i <= n; i++)
    ans += i * coun[i];
  cout << ans;

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

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  long long int a[n + 1];
  for (int i = 0; i < n + 1; i++)
    a[i] = 1;

  a[0] = 0;

  for (int i = 2; i < n + 1; i++) {
    for (int j = i; j < n + 1; j += i) {
      a[j] += 1;
    }
  }

  long long int res = 0;

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

  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#include <numeric>
using namespace std;
const int sz = 1e6 + 5;
ll int arr[sz], arr1[sz];
// ll int arr[100][100]= {0};
bool prime[sz] = {0};
vector<ll int> pr, vec1, vec2;
// vector <pair <int,int>> vec;

void sieve(ll int n) {
  prime[1] = 1;

  for (ll int i = 4; i <= n; i += 2)
    prime[i] = 1;

  for (ll int i = 3; i <= n; i += 2) {
    for (ll int j = i * 3; j <= n; j += (i * 2))
      if (prime[j] == 0)
        prime[j] = 1;
  }

  for (int i = 1; i <= n; i++)
    if (prime[i] == 0)
      pr.push_back(i);
}
unsigned ll int NOD(unsigned ll int n) {

  unsigned ll int res = 1;
  for (unsigned int i = 0; i < pr.size() && pr[i] * pr[i] <= n; i++) {
    if (n % pr[i] == 0) {
      unsigned ll int p = 0; // Counter for power of prime
      while (n % pr[i] == 0) {
        n /= pr[i];
        p++;
      }
      // sqrtn = sqrt ( n );
      p++;      // Increase it by one at end
      res *= p; // Multiply with answer
    }
  }
  if (n != 1) {
    res *= 2; // Remaining prime has power p^1. So multiply with 2/
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  sieve(100000);
  ll int n;
  cin >> n;

  unsigned ll int k = 0;

  for (int i = 1; i <= n; i++) {
    k += (NOD(i) * i);
  }

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

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

long long number[100000000];
void NOD() {

  for (long long i = 1; i <= 10000000; i++) {
    for (long long j = i; j <= 10000000; j += i) {
      number[j]++;
    }
  }
}

int main() {

  NOD();

  long long N;
  cin >> N;

  long long res = 0;
  for (long long i = 1; i <= N; i++) {

    res = res + i * number[i];
  }

  cout << res;

  return 0;
}

Error: TLE

Fixed submission:

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

long long countDiv(long long num) {

  int count = 0;

  for (int i = 1; i * i <= num; i++) {
    if (num % i == 0) {
      count++;

      if (num / i != i) {
        count++;
      }
    }
  }
  return count;
}

int main() {

  long long N;
  cin >> N;

  long long res = 0;
  for (int i = 1; i <= N; i++) {

    res = res + i * countDiv(i);
  }

  cout << res;

  return 0;
}