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

#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
const int MOD = 1000000007;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

ll g(ll k) {
  ll x = k * (k + 1) / 2;
  return x;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  repl(i, 1, n + 1) { ans += i * g(n / i); }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

vector<pair<ll, int>> factor(int n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    int ex = 0;
    while (n % i == 0) {
      ex++;
      n /= i;
    }
    res.push_back({i, ex});
  }
  if (n != 1)
    res.push_back({n, 1});
  return res;
}

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  repl(i, 1, n + 1) {
    vector<pair<ll, int>> fs;
    fs = factor(i);
    ll f = 1;
    for (auto p : fs) {
      int x = p.second;
      f *= x + 1;
    }
    ans += (ll)i * f;
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

class Osa_k {
private:
  int n;
  vector<int> factor;

public:
  // O(NloglogN)
  Osa_k(int _n) : n(_n) {
    factor.assign(n, 0);
    iota(factor.begin(), factor.end(), 0);
    for (int i = 2; i * i < n; i++) {
      if (factor[i] < i)
        continue;
      for (int j = i * i; j < n; j += i) {
        if (factor[j] == j)
          factor[j] = i;
      }
    }
  }

  // O(logV)
  map<int, int> sieve(int v) {
    map<int, int> ret;
    while (v != factor[v]) {
      ret[factor[v]]++;
      v /= factor[v];
    }
    if (v != 1)
      ret[v]++;
    return ret;
  }

  vector<int> divisor(int v) {}

  // O(N)
  vector<int> get_list() {
    vector<int> prime;
    for (int i = 2; i < n; i++)
      if (factor[i] == i)
        prime.emplace_back(i);
    return prime;
  }

  // O(1)
  bool is_prime(int v) {
    if (v <= 1)
      return false;
    return (factor[v] == v);
  }

} fact(10000001);

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    auto v = fact.sieve(i);
    ll ans = 1;
    for (auto j : v)
      ans *= j.second + 1;
    sum += ans * i;
  }
  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

class Osa_k {
private:
  int n;
  vector<int> factor;

public:
  // O(NloglogN)
  Osa_k(int _n) : n(_n) {
    factor.assign(n, 0);
    iota(factor.begin(), factor.end(), 0);
    for (int i = 2; i * i < n; i++) {
      if (factor[i] < i)
        continue;
      for (int j = i * i; j < n; j += i) {
        if (factor[j] == j)
          factor[j] = i;
      }
    }
  }

  // O(logV)
  map<int, int> sieve(int v) {
    map<int, int> ret;
    while (v != factor[v]) {
      ret[factor[v]]++;
      v /= factor[v];
    }
    if (v != 1)
      ret[v]++;
    return ret;
  }

  vector<int> divisor(int v) {}

  // O(N)
  vector<int> get_list() {
    vector<int> prime;
    for (int i = 2; i < n; i++)
      if (factor[i] == i)
        prime.emplace_back(i);
    return prime;
  }

  // O(1)
  bool is_prime(int v) {
    if (v <= 1)
      return false;
    return (factor[v] == v);
  }

} fact(1000001);

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    auto v = fact.sieve(i);
    ll ans = 1;
    for (auto j : v)
      ans *= j.second + 1;
    sum += ans * i;
  }
  cout << sum << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

typedef long long ll;

using namespace std;

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

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long int ll;

int main() {
  ll n = 0, m = 0, k = 0;
  cin >> n >> m >> k;
  ll a[200001] = {0};
  ll b[200001] = {0};
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= m; ++i) {
    cin >> b[i];
    b[i] += b[i - 1];
  }

  int book_num = 0;
  ll min_time = 0, max_time = 0;
  for (int i = 1; i <= 200001; ++i) {
    min_time = min(a[i], b[i]);
    if ((k - min_time) < 0) {
      break;
    }
    max_time = max(a[i], b[i]);
    if ((k - max_time - min_time) < 0) {
      break;
    }
  }
  cout << book_num << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #include<iostream>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;
ll *arr = new ll[10000000 + 100];
// bool isprime[100000000];
/*bool isprime(int n)
{
    if(n<=1) return false;
    else if(n==2) return true;
    else if(n%2==0) return false;
    else
        return true;
}
void sieve(int n)
{
    for(int i=0;i<=n;i++) isprime[i]=true;
    for(int i=2;i*i<=n;i++)
    {
        if(isprime[i])
        {
            for(int j=i*i;j<=n;j=j+i)
            {
                isprime[j]=false;

            }
        }
    }

} */
void SOD(int n) {
  // int *arr=new int[n+1];

  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j = j + i) {
      arr[j] = arr[j] + 1;
    }
  }
  // return arr[n];
}

int main() {
  SOD(10000000);
  // int t;
  // cin>>t;
  // while(t--)
  // {
  ll n;
  cin >> n;
  ll sum = 0;
  // int res=SOD(n);
  // for(int i=0;i<=n;i++) cout<<isprime[i]<<" ";
  // cout<<endl;
  //  cout<<"res: "<<isprime[n]<<endl;
  // cout<<arr[n]-n<<endl;
  // int res=arr[n];
  for (ll i = 1; i <= n; i++) {
    ll temp = i * arr[i];
    sum = sum + temp; //((ll)(i*arr[i]));
  }
  cout << sum << endl;
  // }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #include<iostream>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;
ll *arr = new ll[10000000 + 100];
// bool isprime[100000000];
/*bool isprime(int n)
{
    if(n<=1) return false;
    else if(n==2) return true;
    else if(n%2==0) return false;
    else
        return true;
}
void sieve(int n)
{
    for(int i=0;i<=n;i++) isprime[i]=true;
    for(int i=2;i*i<=n;i++)
    {
        if(isprime[i])
        {
            for(int j=i*i;j<=n;j=j+i)
            {
                isprime[j]=false;

            }
        }
    }

} */
void SOD(int n) {
  // int *arr=new int[n+1];

  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j = j + i) {
      arr[j] = arr[j] + 1;
    }
  }
  // return arr[n];
}

int main() {
  SOD(10000000);
  int t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    ll sum = 0;
    // int res=SOD(n);
    // for(int i=0;i<=n;i++) cout<<isprime[i]<<" ";
    // cout<<endl;
    //  cout<<"res: "<<isprime[n]<<endl;
    // cout<<arr[n]-n<<endl;
    // int res=arr[n];
    for (ll i = 1; i <= n; i++) {
      ll temp = i * arr[i];
      sum = sum + temp; //((ll)(i*arr[i]));
    }
    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;
#define all(v) v.begin(), v.end()

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

  vector<ll> a(10000001);
  for (ll i = 1; i <= 10000000; i++) {
    ll max = 10000000 / i;
    for (ll j = 1; j <= max; j++) {
      a[j * i]++;
    }
  }

  for (ll i = 1; i <= n; i++) {
    ll yaku;
    yaku = a[i];
    sum += i * yaku;
  }

  cout << sum << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()

ll yakusuu(ll n) {
  ll count = 0;
  for (ll i = 1; i <= n; i++) {
    if (n % i == 0)
      count++;
  }
  return count;
}

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

  for (ll i = 1; i <= n; i++) {
    ll yaku;
    yaku = yakusuu(i);
    sum += i * yaku;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define vv vector<ll>
#define fr(i, x) for (int i = 0; i < x; i++)
#define MAX 10000005
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {

  if (a.first == b.first)
    return a.second < b.second;
  return (a.first < b.first);
}

ll a[MAX];
void sieve() {
  for (int i = 1; i < MAX; i++) {
    for (int j = i; j <= MAX; j += i) {
      a[j]++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, x, m, r, cnt = 0, k, y;

  cin >> n;
  sieve();
  for (int i = 1; i <= n; i++) {
    cnt += (i * a[i]);
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define fr for (int i = 0; i < n; i++)
#define pb push_back
void printVector(vector<char> x) {
  for (auto i : x) {
    cout << i << " ";
  }
  cout << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  map<int, int> mapping;
  map<int, int>::iterator itr;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (i % j == 0) {
        mapping[i]++;
      }
    }
  }
  unsigned long long int sum = 0;
  string result;
  for (itr = mapping.begin(); itr != mapping.end(); itr++) {
    // cout << itr->first << " " << itr->second << endl;
    sum += (itr->first * itr->second);
  }
  cout << to_string(sum) << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define N 10000005
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
typedef long long ll;
ll cnt[N];
int main() {
  FAST;
  ll n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j = j + i) {
      cnt[j]++;
    }
  }
  ll ans = 0LL;
  for (ll i = 1; i <= n; i++)
    ans += (i * cnt[i]);
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define N 1e7 + 2
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
typedef long long ll;
map<ll, ll> cnt;
int main() {
  FAST;
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i)
      cnt[j]++;
  }
  ll ans = 0LL;
  for (ll i = 1; i <= n; i++)
    ans += (i * cnt[i]);
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, a, n) for (int i = a; i < n; i++)
#define been(ix) (ix).begin(), (ix).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001;
typedef pair<int, int> P;
#define foreach(ix, i) for (auto &(ix) : (i))
typedef long double ld;
const int mod = 1000000007;
const double PI = acos(-1);
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  rep(i, n) {
    ll x = i + 1;
    ll c = n / x;
    ans += ((x + (x * c)) * c) / 2;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, a, n) for (int i = a; i < n; i++)
#define been(ix) (ix).begin(), (ix).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001;
typedef pair<int, int> P;
#define foreach(ix, i) for (auto &(ix) : (i))
typedef long double ld;
const int mod = 1000000007;
const double PI = acos(-1);
vector<int> ns(1000005, 0), er;
int main() {
  int n;
  cin >> n;
  ll ans = 1;
  ns[1] == 1;
  rep(i, n) {
    if (i == 0)
      continue;
    int x = i + 1, cnt = 0;
    ;
    for (int j = 2; j <= sqrt(x); j++) {
      if (x % j == 0) {
        cnt = j;
        break;
      }
    }
    if (cnt == 0) {
      ns[x] = 2;
      ans += x * 2;
    } else {
      int y = ns[x / cnt];
      int z = x / cnt;
      int me = 0;
      while (z % cnt == 0) {
        me++;
        z /= cnt;
      }
      ns[x] = (y / (me + 1)) * (me + 2);
      ans += x * ns[x];
    }
    // cout<<ans<<endl;
  }
  cout << ans << endl;
}
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++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<ll, int>;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<ll, int>;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i])
        continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i * i; j <= n; j += i) {
        if (!f[j])
          f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0)
      return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll, int>> factor(ll x) {
    vector<pair<ll, int>> res;
    for (int p : primes) {
      int y = 0;
      while (x % p == 0)
        x /= p, ++y;
      if (y != 0)
        res.emplace_back(p, y);
    }
    if (x != 1)
      res.emplace_back(x, 1);
    return res;
  }
};

vector<P> prime_factor(int n) {
  vector<P> res;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    int cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    res.push_back(P(i, cnt));
  }
  if (n != 1)
    res.push_back(P(n, 1)); // nが素数の時
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  Sieve s(n + 5);
  for (ll k = n; k >= 1; k--) {
    vector<P> vec = s.factor(k);
    ll num = 1;
    for (auto p : vec) {
      num *= (p.second + 1);
    }
    ans += k * num;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define mx 10000005
#define ll long long
vector<int> prime(10000000);
bool vis[10000005];
int a[10000005], store[10000005], cn;
void sieve() {
  vis[0] = vis[1] = true;
  for (int i = 2; i * i < mx; i++) {
    if (!vis[i]) {
      prime[cn++] = i;
      for (int j = i * 2; j < mx; j += i)
        vis[j] = true;
    }
  }
}

int main() {
  sieve();
  ll n;
  cin >> n;
  ll ans = 1;
  for (ll i = 2; i <= n; i++) {
    ll p = i;
    ll tmp = 1;
    for (ll j = 0; prime[j] * prime[j] * prime[j] <= p; j++) {
      ll cnt = 0;
      if (p % prime[j] == 0) {
        while (p % prime[j] == 0) {
          cnt++;
          p /= prime[j];
        }
        tmp *= (cnt + 1);
      }
    }
    if (p > 1) {
      ll sq = sqrt(p);
      if (vis[p] == 0)
        tmp *= 2;
      else if (sq * sq == p)
        tmp *= 3;
      else
        tmp *= 4;
    }
    ans += (tmp * i);
  }

  printf("%lld\\n", ans);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mx 10005
#define ll long long
vector<int> prime;
bool vis[10000005];
int a[10000005], store[10000005];
void sieve() {
  for (int i = 2; i < mx; i++) {
    if (!vis[i]) {
      prime.push_back(i);
      for (int j = i * 2; j < mx; j += i)
        vis[j] = true;
    }
  }
}

int main() {
  sieve();
  ll n;
  cin >> n;
  ll ans = 1;
  for (ll i = 2; i <= n; i++) {
    ll p = i;
    ll tmp = 1;
    for (ll j = 0; j < prime.size() && p > 1 && prime[j] * prime[j] <= p; j++) {
      ll cnt = 0;
      if (p % prime[j] == 0) {
        while (p % prime[j] == 0) {
          cnt++;
          p /= prime[j];
        }
        tmp *= (cnt + 1);
      }
    }
    if (p > 1) {
      tmp *= 2;
    }
    ans += tmp * i;
  }

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
const int mxN = 1e7;
ll dp[mxN + 3];
using namespace std;
ll f(ll d) {
  ll num = 0;
  for (int i = 1; i < sqrt(d); i++)
    if (d % i == 0) {
      num++;
    }
  num *= 2;
  ll s = sqrt(d);
  if (d == s * s)
    num++;
  return num;
}
int main() {
  dp[1] = 1;
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    dp[i] += dp[i - 1] + i * f(i);
  }
  cout << dp[n];
}
Problem p02624 (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))

int main() {
  ll ans = 0;
  int N;
  cin >> N;
  rep(i, N + 1) {
    if (i != 0) {
      ll n = N / i;
      ans += n * (i + i * n) / 2;
    }
  }

  cout << ans << endl;
}

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))
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end()); // 昇順に並べる
  return ret;
}
int main() {
  ll ans = 0;
  int N;
  cin >> N;
  vector<int> L(N + 1, 0);
  for (int i = N; i > 0; i--) {
    if (L[i] == 0) {
      vector<ll> p = divisor(i);
      L[i] = p.size();
      // for(int j = p.size() - 1; j >= 0; j--) {
      //     if(L[p[j]] != 0)
      //         break;
      //     else {
      //         L[p[j]] = j + 1;
      //     }
      // }
    }
  }
  for (int i = 1; i <= N; i++) {
    ans += i * L[i];
    // cout << L[i] << " ";
  }

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

#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

long long divisor(long long n) {
  long long ret = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ++ret;
      if (i * i != n)
        ++ret;
    }
  }
  return ret;
}

int main(void) {
  long N;

  cin >> N;

  long ans = 0;

  for (long i = 1; i < N + 1; i++) {
    ans = ans + 0.5 * i * floor(N / i) * (floor(N / i) + 1);
  }

  cout << ans << "\\n";
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

long long divisor(long long n) {
  long long ret = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ++ret;
      if (i * i != n)
        ++ret;
    }
  }
  return ret;
}

int main(void) {
  long N;

  cin >> N;

  long long ans = 1;

  for (long i = 2; i < N + 1; i++) {
    ans = ans + i * divisor((long long)i);
  }

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

#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 / gcd(a, b) * b; }

// 約数の全列挙
vector<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);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  cout << fixed << setprecision(15);
  ll N;
  cin >> N;

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

Error: TLE

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 / gcd(a, b) * b; }

// 約数の全列挙
vector<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);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  cout << fixed << setprecision(15);
  ll N;
  cin >> N;

  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    vector<ll> P = divisor(i);

    ans += i * P.size();
  }
  cout << ans << endl;
  return 0;
}
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;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;

int P_SIZE_MAX = 10000000;
vector<int> P;

void Eratosthenes(int N) {
  vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.push_back(i);
    }
  }
}

int func(int k) {
  int cntSum = 1;
  int y = k;
  for (int i = 0; P[i] * P[i] <= k; i++) {
    int x = k;
    int divCnt = 0;
    while (x > 1) {
      if (x % P[i] == 0) {
        divCnt++;
        x /= P[i];
        y /= P[i];
      } else {
        break;
      }
    }
    cntSum *= divCnt + 1;
  }
  if (y > 1)
    cntSum *= 2;
  return cntSum;
}

int main(void) {
  int n;
  cin >> n;
  Eratosthenes(P_SIZE_MAX);
  ll ans = 0;
  for (int i = 1; i <= n; i++)
    ans += (ll)func(i) * i;
  cout << ans << endl;
  return 0;
}