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

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

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

  ll n, ans = 0;
  cin >> n;
  for (ll i = 1; i <= n; ++i) {
    ll y = n / i;
    ans += (y + 1) * y * i / 2;
  }
  cout << ans << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

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

ll enum_divisors(ll N) {
  ll res = 0;
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      ++res;
      // 重複しないならば i の相方である N/i も push
      if (N / i != i)
        ++res;
    }
  }
  return res;
}

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

  ll n, ans = 0;
  cin >> n;
  for (ll i = 1; i <= n; ++i) {
    ans += i * enum_divisors(i);
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int util(int n, int i) {
  int count = 0;
  while (n > 0 && n % i == 0) {
    count++;
    n /= i;
  }
  return count + 1;
}
int main() {
  int n;
  cin >> n;
  vector<int> factors(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i)
      factors[j]++;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++)
    ans += (1L * i * factors[i]);
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int util(int n, int i) {
  int count = 0;
  while (n > 0 && n % i == 0) {
    count++;
    n /= i;
  }
  return count + 1;
}
int main() {
  int n;
  cin >> n;
  vector<bool> isPrime(n + 1, 1);
  for (int i = 2; i <= n; i++) {
    if (isPrime[i]) {
      for (int j = 2 * i; j <= n; j += i)
        isPrime[j] = 0;
    }
  }
  vector<int> prime;
  for (int i = 2; i <= n; i++)
    if (isPrime[i])
      prime.push_back(i);
  ll ans = 0;
  // for(int i:prime)
  // cout<<i<<" ";
  // cout<<endl;
  for (int i = 1; i <= n; i++) {
    int count = 1;
    for (int j = 0; j < prime.size(); j++) {
      if (prime[j] > i)
        break;
      if (i % prime[j] == 0)
        count *= util(i, prime[j]);
    }
    // cout<<i<<" "<<count<<endl;
    ans += i * count;
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  ll n, sum = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    sum = sum + (i * (n / i) * (n / i + 1)) / 2;
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;

int main() {

  long long int i, l, r, j, ans, cnt = 0, res, n, m, t = 0;
  cin >> n;
  ans = 1;
  for (i = 2; i <= n; i++) {
    cnt = 2;
    res = sqrt(i);
    for (j = 2; j <= res; j++) {
      if (i % j == 0) {
        cnt += 2;
        if (i / j == j)
          cnt--;
      }
    }
    ans += cnt * i;
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

const int SIZE = 1e7 + 7;
int nod[SIZE];
ll ans;
class divisor {
public:
  divisor() {
    for (int i = 1; i <= SIZE; i++) {
      for (int j = 1; i * j <= SIZE; j++) {
        nod[i * j]++;
      }
    }
  }
};

divisor obj;

void solve(int num) {
  for (int i = 1; i <= num; i++) {
    ans += 1LL * i * nod[i];
  }
}

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

  //	freopen("input.txt", "r", stdin);
  //	freopen("output.txt", "w", stdout);

  int num;
  cin >> num;
  solve(num);
  cout << ans << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

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

int f(int x) {
  int fact = 0;
  for (int i = 1; i <= x; i++) {
    if (x % i == 0) {
      fact++;
    }
  }
  return fact;
}

int main() {
  int N;
  cin >> N;
  int tot = 0;
  for (int i = 1; i <= N; i++) {
    tot += (i * f(i));
  }

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

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

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

ll calc_ans(ll x) {
  ll ans = 0;
  for (int i = 1; i <= x; ++i) {
    ans += sn(x / i) * i;
  }

  return ans;
}

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

  cout << calc_ans(N) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

long long calc_ans(long long N) {
  long long ans = 0;

  for (int i = 1; i <= N; ++i) {
    int cnt = 0;
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        if (i / j == j)
          cnt += 1;
        else
          cnt += 2;
      }
    }
    ans += (long long)i * cnt;
  }

  return ans;
}

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

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ll res = (N / i) * (i + (i * (N / i)));
    res /= 2;
    ans += res;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
ll enum_divisors(ll N) {
  ll res = 0;
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      res++;
      if (N / i != i)
        res++;
    }
  }
  return res;
}
int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ans += (enum_divisors(i)) * i;
  }
  cout << ans << 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 < (n); i++)
typedef long long ll;
vector<int> num(10000001, 2);

void sieve(ll n) {
  for (int i = 2; i * i <= n; ++i) {
    for (int j = i; i * j <= n; ++j) {
      num.at(i * j) += 2;
      if (i == j)
        num.at(i * j)--;
    }
  }
  num.at(1) = 1;
}

int main() {
  ll n, ans = 0;
  cin >> n;
  sieve(n);
  for (ll i = 1; i <= n; i++)
    ans += i * (ll)num.at(i);
  cout << ans;
}

Error: TLE

Fixed submission:

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

// nの素数判定。O(√n)。
bool is_prime(ll n) {
  for (ll i = 2; i * i <= n; i++)
    if (!(n % i))
      return false;
  return n != 1;
}

// 約数列挙。O(√n)。
ll divisor(ll n) {
  vector<ll> rtn;
  for (ll i = 1; i * i <= n; i++)
    if (!(n % i)) {
      rtn.push_back(i);
      if (i != n / i)
        rtn.push_back(n / i);
    }
  sort(rtn.begin(), rtn.end());
  return rtn.size();
}

// 素因数分解。O(√n)。
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> rtn;
  for (ll i = 2; i * i <= n; i++) {
    while (!(n % i)) {
      ++rtn[i];
      n /= i;
    }
  }
  if (n != 1)
    rtn[n] = 1;
  return rtn;
}

// エラストテネスの篩。n以下の素数をvectorで返す。O(n log log n)。
vector<bool> sieve(ll n) {
  vector<bool> rtn(n + 1, true);
  rtn.at(0) = rtn.at(1) = false;
  for (int i = 2; i * i <= n; ++i)
    if (rtn.at(i)) {
      for (int j = 2; i * j <= n; ++j)
        rtn.at(i * j) = false;
    }
  return rtn;
}

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

  // エラストテネスの篩実行
  vector<bool> Sieve = sieve(n);
  // cout<<"[sieve]        ";
  // REP(i,n) if(Sieve.at(i)) cout<<i<<" ";
  // cout<<endl;
  for (int i = 1; i <= n; i++) {
    if (i == 1)
      ans += 1;
    else if (Sieve.at(i))
      ans += i * 2;
    else {
      // 約数列挙実行
      ans += i * divisor(i);
      // cout<<"[divisor]      ";
      // cout<<endl;
    }
  }
  cout << ans;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

void solve(vector<string> arr) {
  /*
  for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
          cout << arr[i][j];
          if ((j+1)%3 == 0) {
              cout << " ";
          }
      }
      cout << endl;
      if ((i+1)%3 == 0) {
          cout << endl;
      }
  }
  */

  int i = 0;
  for (int k = 0; k < 3; k++) {
    int tmp = k;
    for (int j = 1; j <= 3; j++) {
      arr[i][tmp] = arr[i][tmp] == '1' ? '2' : '1';
      tmp += 3;
      i += 1;
    }
  }

  /*
  for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
          cout << arr[i][j];
          if ((j+1)%3 == 0) {
              cout << " ";
          }
      }
      cout << endl;
      if ((i+1)%3 == 0) {
          cout << endl;
      }
  }
  */
  for (string s : arr) {
    cout << s << endl;
  }
}
long long int num(long long int n) {
  long long int toRet = 0;
  for (long long int i = 1; i <= (long long int)sqrt(n); i++) {
    if (n % i == 0) {
      toRet += i == n / i ? 1 : 2;
    }
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

void solve(vector<string> arr) {
  /*
  for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
          cout << arr[i][j];
          if ((j+1)%3 == 0) {
              cout << " ";
          }
      }
      cout << endl;
      if ((i+1)%3 == 0) {
          cout << endl;
      }
  }
  */

  int i = 0;
  for (int k = 0; k < 3; k++) {
    int tmp = k;
    for (int j = 1; j <= 3; j++) {
      arr[i][tmp] = arr[i][tmp] == '1' ? '2' : '1';
      tmp += 3;
      i += 1;
    }
  }

  /*
  for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
          cout << arr[i][j];
          if ((j+1)%3 == 0) {
              cout << " ";
          }
      }
      cout << endl;
      if ((i+1)%3 == 0) {
          cout << endl;
      }
  }
  */
  for (string s : arr) {
    cout << s << endl;
  }
}
long long int num(long long int n) {
  long long int toRet = 0;
  for (long long int i = 1; i <= (long long int)sqrt(n); i++) {
    if (n % i == 0) {
      toRet += i == n / i ? 1 : 2;
    }
  }

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

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define MAX 100005
#define mod 1000000007
#define sp fixed << setprecision(12)
using namespace std;

void solve() {
  ll n;
  cin >> n;
  vector<ll> v(n + 1, 2);
  ll ans = 1;
  v[1] = 1;
  for (ll i = 2; i <= n; i++) {
    for (ll j = 2 * i; j <= n; j += i) {
      v[j]++;
    }
  }
  for (ll i = 2; i <= n; i++) {
    ans += (i * v[i]);
    // cout<<v[i]<<" ";
  }
  cout << ans << "\\n";
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // double    pi=3.14159265358979323846;

  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define MAX 100005
#define mod 1000000007
#define sp fixed << setprecision(12)
using namespace std;

void solve() {
  ll n;
  cin >> n;
  vector<ll> v(n + 1, 2);
  ll ans = 0;
  v[1] = 1;
  for (ll i = 2; i <= n; i++) {
    for (ll j = 2 * i; j <= n; j += i) {
      v[j]++;
      if ((i / j) > (j * j)) {
        v[j]++;
      }
    }
  }
  for (ll i = 1; i <= n; i++) {
    ans += (i * v[i]);
    // cout<<v[i]<<" ";
  }
  cout << ans << "\\n";
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // double    pi=3.14159265358979323846;

  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 nl "\\n"
using namespace std;
void solve() {
  int n;
  scanf("%d", &n);

  vector<int> div(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j += i)
      div[j]++;
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++)
    ans += (i * (ll)div[i]);

  printf("%lld\\n", ans);
}
int main() {
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll unsigned long long
#define nl "\\n"
using namespace std;
const ll N = 1e7 + 1;
ll value[N];
bool vis[N];
vector<ll> prime;
void sieve() {
  for (ll i = 3; i * i <= N; i += 2) {
    if (!vis[i]) {
      for (ll j = i * i; j <= N; j += 2 * i)
        vis[j] = true;
    }
  }
  prime.push_back(2LL);
  for (ll i = 3; i < N; i += 2)
    if (!vis[i])
      prime.push_back(i);
}
ll NOD(ll n) {
  ll ret = 1;
  ll root = sqrt(n);
  for (ll i = 0; i < prime.size() && prime[i] <= root; i++) {
    if (n % prime[i] == 0) {
      int cnt = 1;
      while (n % prime[i] == 0) {
        cnt++;
        n /= prime[i];
      }
      ret *= cnt;
      root = sqrt(n);
    }
  }
  if (n > 1)
    ret *= 2;
  return ret;
}
void DivCal() {
  sieve();
  value[1] = 1;
  for (ll k = 2; k < N; k++)
    value[k] = NOD(k) * k + value[k - 1];
}
void solve() {
  ll n;
  scanf("%lld", &n);
  printf("%lld\\n", value[n]);
}
int main() {
  DivCal();
  solve();
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  ll n;
  cin >> n;
  ll i, j, ans = 0;
  for (i = 1; i <= n; i++) {
    ll t = n / i;
    ans = ans + t * (i + n - n % i) / 2;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

// program for finding no. of divisors
int divCount(int n) {
  // sieve method for prime calculation
  bool hash[n + 1];
  memset(hash, true, sizeof(hash));
  for (int p = 2; p * p < n; p++)
    if (hash[p] == true)
      for (int i = p * 2; i < n; i += p)
        hash[i] = false;

  // Traversing through all prime numbers
  int total = 1;
  for (int p = 2; p <= n; p++) {
    if (hash[p]) {

      // calculate number of divisor
      // with formula total div =
      // (p1+1) * (p2+1) *.....* (pn+1)
      // where n = (a1^p1)*(a2^p2)....
      // *(an^pn) ai being prime divisor
      // for n and pi are their respective
      // power in factorization
      int count = 0;
      if (n % p == 0) {
        while (n % p == 0) {
          n = n / p;
          count++;
        }
        total = total * (count + 1);
      }
    }
  }
  return total;
}

// driver program
int main() {
  int n;
  cin >> n;
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = ans + (long long int)(i * divCount(i));
  }
  cout << ans;
  return 0;
}
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);
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j += i) {
      V.at(j)++;
    }
  }
  long ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += (long)i * V.at(i);
  }
  cout << ans << "\\n";
}

Error: TLE

Fixed submission:

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

int div(int n) {
  int cnt = 0;
  for (long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      cnt += 2;
      if (i * i == n)
        cnt--;
    }
  }
  return cnt;
}

int main() {
  int N;
  cin >> N;
  long ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += div(i) * i;
  }
  cout << ans << "\\n";
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int main() {
  ll n, ans = 0, temp;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    temp = n / i;
    ans += i * ((temp * (temp + 1)) / 2);
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int divisors(ll x) {
  ll i, div = 0;
  for (i = 1; i <= x; i++) {
    if (x % i == 0)
      ++div;
    continue;
  }
  return div;
}

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define sc second
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

const int MAXN = 1e7;
int ct_div[MAXN + 5];

int main() {
  ll ans = 0;
  int n;
  scanf("%d", &n);

  for (int i = 1; i <= n; i++) {
    for (int j = 1; i * j <= n; j++) {
      ct_div[i * j]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    ans += 1LL * i * ct_div[i];
  }
  printf("%lld\\n", ans);
}

Error: TLE

Fixed submission:


// not done yet
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int div(ll i) {
  ll c = 2, j;
  if (i == 1)
    return 1;
  for (j = 2; j * j <= i; j++) {
    if ((i % j == 0) && (j * j == i))
      c += 1;
    else if (i % j == 0)
      c += 2;
  }
  return c;
}

int main() {
  ll n, s = 0, i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    s = s + (div(i) * i);
  }
  cout << s << 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 < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

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


Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>

#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

signed main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int m = 1; m <= (int)sqrt(N); ++m) {
    ans += m * (m + N / m) * (N / m + 1 - m);
  }
  int n2 = (int)sqrt(N);
  ans -= n2 * (n2 + 1) * (2 * n2 + 1) / 6;
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

int f[10001000];
vector<int> primes;

signed main() {
  primes.push_back(2);
  for (int i = 3; i <= (int)sqrt(10000000) + 10; i += 2) {
    bool isPrime = true;
    for (int p : primes) {
      if (i % p == 0) {
        isPrime = false;
        break;
      }
    }
    if (isPrime) {
      primes.push_back(i);
    }
  }
  f[1] = 1;
  f[2] = 2;

  int N;
  cin >> N;
  for (int i = 3; i <= N; ++i) {
    bool isPrime = true;
    for (int p : primes) {
      if (i == p)
        break;
      if (i % p == 0) {
        int cnt = 0;
        int i2 = i;
        while (i2 % p == 0) {
          i2 /= p;
          cnt++;
        }
        isPrime = false;
        f[i] = (cnt + 1) * f[i2];
        break;
      }
    }
    if (isPrime) {
      f[i] = 2;
    }
  }
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    ans += i * f[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

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

const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 1e7 + 1;
const long double PI = acos(-1);

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

  ll n, ans = 0, x;
  cin >> n;

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

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

const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 1e7 + 1;
const long double PI = acos(-1);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n, ans = 0;
  scanf("%ll", &n);

  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      ans += j;
    }
  }

  printf("%lld\\n", ans);
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
#define DBG(x)                                                                 \\
  (void)(cout << "L" << __LINE__ << ": " << #x << " = " << (x) << '\\n')
#define Lower_bound(v, x)                                                      \\
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \\
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 11000000;
int f[maxn];
void run_case() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      f[j]++;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += 1ll * i * f[i];
  }
  cout << ans << "\\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setiosflags(ios::fixed) << setprecision(12);
  run_case();
  cout.flush();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, count = 0, sum = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    count = 0;
    for (j = 1; j <= i; j++) {
      if (i % j == 0)
        count++;
    }
    sum = sum + (i * count);
  }
  cout << sum;
  return 0;
}