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

/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a, b) __gcd(a, b);
#define endl "\\n"
#define FRU freopen("out.txt", "w", stdout)
#define FRO freopen("in.txt", "r", stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN 100001
#define ar array
const int mxN = 2e5;
const int MOD = 1e9 + 7;
const int num = 1e7 + 3;
ll a[num] = {0};
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
// Don't hesitate to ask me if you don't understand my code.......Happy
// coding,Tahmid...;
int main() {
  fastio;
  ll n;
  cin >> n;
  ll i, j;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  ll ans = 0;
  for (i = 1; i <= n; i++) {
    ans += i * a[i];
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a, b) __gcd(a, b);
#define endl "\\n"
#define FRU freopen("out.txt", "w", stdout)
#define FRO freopen("in.txt", "r", stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN 100001
const int mx = (int)1e7;
// Don't hesitate to ask me if you don't understand my code.......Happy
// coding,Tahmid...;
bool prime[mx + 1];
void seive() {
  ll i, j;
  memset(prime, 1, sizeof(prime));
  for (i = 2; i * i < mx; i++) {
    if (prime[i]) {
      for (j = i * i; j < mx; j += i) {
        if (prime[j])
          prime[j] = 0;
      }
    }
  }
}
ll cdivisor(ll x) {
  ll c, div = 1, i;
  for (i = 2; i <= x; i++) {
    c = 0;
    if (prime[i]) {
      while (x % i == 0) {
        c++;
        x = x / i;
      }
    }
    div *= (c + 1);
  }
  return div;
}
int main() {
  fastio;
  seive();
  ll n, i;
  cin >> n;
  ll ans = 0;
  for (i = 1; i <= n; i++) {
    ans += i * cdivisor(i);
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int N = 10000005;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n + 1] = {0};
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
      for (ll j = i; j <= n; j += i) {
        a[j]++;
      }
    }
    for (ll i = 1; i <= n; i++) {
      ans += i * a[i];
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

const int N = 100005;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    ll n;
    cin >> n;
    ll i = 1;
    ll ans = 0;
    while (i <= n) {
      ll cnt = 0;
      ll n1 = i;
      for (ll j = 1; j * j <= n1; j++) {
        if (n1 % j == 0) {
          if (n1 / j == j)
            cnt++;

          else
            cnt = cnt + 2;
        }
      }
      // cout<<i<<" "<<cnt<<endl;
      ans += i * cnt;
      i++;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

ll dp[10000010];
ll num_div(int N) {
  int n = N;
  ll res = 1;
  for (int i = 2; i * i <= n; ++i) {
    int cnt = 0;
    while (n % i == 0) {
      ++cnt, n /= i;
    }
    res *= (cnt + 1);
    if (dp[n])
      return dp[N] = res * dp[n];
  }
  if (n != 1)
    res *= 2;
  return dp[N] = res;
}

int main() {
  int N;
  cin >> N;
  ll ans = 1;
  for (int k = 2; k <= N; ++k) {
    ans += k * num_div(k);
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

#define FAST_IO                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MAXN = 2e5 + 5;
const ll MOD = 998244353;
const ll INF = INT64_MAX;

random_device rd;
mt19937 rnd(rd());

signed main() {
  FAST_IO;
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      ans += j;
    }
  }
  cout << ans << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

#define FAST_IO                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MAXN = 2e5 + 5;
const ll MOD = 998244353;
const ll INF = INT64_MAX;

random_device rd;
mt19937 rnd(rd());

signed main() {
  FAST_IO;
  int n;
  cin >> n;
  vector<int> primes;
  int d[n + 1];
  for (int i = 2; i <= n; i++) {
    if (!d[i]) {
      d[i] = i;
      primes.pb(i);
    }
    for (auto x : primes) {
      if (x * i > n || x > d[i]) {
        break;
      }
      d[i * x] = x;
    }
  }
  int ans = 0;
  for (int k = 1; k <= n; k++) {
    int st = 1;
    int n1 = k;
    int lst = k;
    while (n1 > 1) {
      int stnow = 0;
      int kek = d[n1];
      while (n1 % kek == 0) {
        stnow++;
        n1 /= kek;
      }
      stnow++;
      st *= stnow;
    }
    // if (k != 1) {
    // 	st--;
    // }
    ans += st * k;
  }
  cout << ans << "\\n";
  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)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
#define yn                                                                     \\
  { puts("Yes"); }                                                             \\
  else {                                                                       \\
    puts("No");                                                                \\
  }
#define MAX_N 10000005

ll f[MAX_N] = {};
int main() {
  ll n;
  cin >> n;

  ll ans = 0;
  srep(i, 1, n + 1) {
    int ii = i;
    while (ii <= n) {
      ans += ii;
      // f[ii]++;
      ii += i;
    }
  }

  /*
  srep(i,1,n+1){
      ll ii = i;
      ans += f[i] * ii;
  }
  */
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
#define yn                                                                     \\
  { puts("Yes"); }                                                             \\
  else {                                                                       \\
    puts("No");                                                                \\
  }
#define MAX_N 10000005

ll f[MAX_N] = {};
int main() {
  ll n;
  cin >> n;

  ll ans = 0;
  srep(i, 1, n + 1) {
    int ii = i;
    while (ii <= n) {
      ans += ii;
      // f[ii]++;
      // ii += i;
    }
  }

  /*
  srep(i,1,n+1){
      ll ii = i;
      ans += f[i] * ii;
  }
  */
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(x) (int)x.size()
#define yes cout << "Yes\\n"
#define no cout << "No\\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ft first
#define sd second
#define FOR(i, b, n) for (int i = b; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
using pii = pair<int, int>;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vd = vector<double>;
mt19937_64 rnd(time(0));
int N = 1e7 + 1, n, ans = 0;
void start() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  // cerr << fixed << setprecision(10);
#ifdef MY
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  N = 100;
#endif
}
vi a(N);
signed main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; j += i)
      a[j]++;
    ans += i * a[i];
  }
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(x) (int)x.size()
#define yes cout << "Yes\\n"
#define no cout << "No\\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ft first
#define sd second
#define FOR(i, b, n) for (int i = b; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
using pii = pair<int, int>;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vd = vector<double>;
mt19937_64 rnd(time(0));

void start() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  // cerr << fixed << setprecision(10);
#ifdef MY
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
}

signed main() {
  int k, s, c, a = 0;
  cin >> k;
  for (int n = 1; n <= k; ++n) {
    s = sqrt(n), c = 0;
    for (int i = 1; i <= s; ++i) {

      if (n % i == 0) {
        c++;

        if (n / i != i)
          c++;
      }
    }
    a += n * c;
  }
  cout << a;
}
Problem p02624 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

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

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

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

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;
using P = pair<int, int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1 << 30;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

Error: TLE

Fixed submission:

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

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;
using P = pair<int, int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1 << 30;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll N;
  cin >> N;
  ll ans = 1LL;
  vector<unordered_map<ll, ll>> vm(N + 1);
  vector<ll> sosu;
  vector<bool> vb(10000010, true);
  rep(i, 10000010) {
    if (i < 2)
      continue;
    if (!vb[i])
      continue;
    sosu.push_back(i);
    for (int j = i * 2; j < 10000010; j += i) {
      vb[j] = false;
    }
  }
  for (ll i = 2LL; i <= N; i++) {
    ll t = i;
    if (vb[i])
      vm[i][i]++;
    else {
      for (auto j : sosu) {
        if (j * j > t)
          break;
        if (t % j == 0) {
          vm[i] = vm[i / j];
          vm[i][j]++;
          break;
        }
      }
    }
  }
  for (ll i = 2; i < N + 1; i++) {
    ll cnt = 1;
    for (auto y : vm[i]) {
      cnt *= y.second + 1;
    }
    ans += i * cnt;
  }
  cout << ans << endl;
}
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 REPR(i, n, m) for (int i = (n); i >= (m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;

int main() {

  LL n;
  cin >> n;

  LL ans = 0;

  for (LL i = 1; i <= n; i++) {
    LL num = n / i;
    LL end = num * i;
    ans += num * (i + end) / 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)
#define REPR(i, n, m) for (int i = (n); i >= (m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();
const unsigned long long int ULLINF =
    numeric_limits<unsigned long long int>::max();

int main() {

  LL n;
  cin >> n;

  LL ans = 0;

  for (LL i = 1; i <= n; i++) {
    for (LL j = 1; j <= n; j++) {
      if (i % j == 0)
        ans += i;
    }
  }

  cout << ans << endl;

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


// D - Sum of Divisors

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

  ll ans = 0;

  for (int j = 1; j <= N; j++) {
    /*
    cout << "j=" << j;
    for (int i=1; i<=N; i++) {
            if (i % j == 0) {
                    ans += i;
                    cout << " " << i;
            }
    }
    cout << endl;
    */

    // 等差数列の和
    ll n = N / j;
    ll a = j;
    ll l = a + j * (n - 1);

    ans += n * (a + l) / 2;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:


//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;

  for (ll p = 2; p * p <= n; ++p) {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }

  if (n != 1)
    res.push_back(make_pair(n, 1));

  return res;
}

// 約数の個数を求める
ll count_divisor(ll k) {
  vector<pair<ll, ll>> primes = prime_factorize(k);

  ll result = 1;
  for (auto pair : primes) {
    int count = pair.second;
    result = (result * (count + 1));
  }

  return result;
}

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

  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += i * count_divisor(i);
  }

  cout << ans << endl;

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

#include <iostream>
using namespace std;
using ll = long long;

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

int main(void) {
  ll n;
  cin >> n;

  ll res = 0;
  for (ll d = 1; d <= n; d++)
    res += d * sum(n / d);

  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
using ll = long long;
constexpr int MAXN = 1e7 + 1;

int ndiv(int n) {
  int res = 2;
  int d;
  for (d = 2; d * d < n; d++)
    if (n % d == 0)
      res += 2;

  if (d * d == n)
    res++;

  return res;
}

int cdiv[MAXN];

int main(void) {
  cdiv[1] = 1;
  for (int i = 2; i < MAXN; i++)
    cdiv[i] = ndiv(i);

  ll res = 1;
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++)
    res += i * cdiv[i];

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

#include <bits/stdc++.h>
#define endl "\\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1e18;
// const ll mod = 1000000007;
ll N;
ll num[10010000];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  for (ll i = 1; i <= N; i++) {
    for (ll j = i; j <= N; j += i) {
      num[j]++;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ans += i * num[i];
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> using numr = std::numeric_limits<T>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> num(10000100);
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      // if(i % j != 0) continue;
      if (i % j == 0)
        num[i]++;
    }
  }
  for (int i = 0; i < num.size(); i++) {
    ans += i * num[i];
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded



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

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

  cout << ans;
}

Error: TLE

Fixed submission:

// #include<bits/stdc++.h>
// using namespace std;
// typedef long long ll;
//
// int main()
//{
// int n,m;
// ll k;
// cin>>n>>m>>k;
// ll a[n];
// ll b[m];
// for(int i=0;i<n;i++)
//     cin>>a[i];
// for(int i=0;i<m;i++)
//     cin>>b[i];
// int ai=0,bi=0;
// int ans=0;
// while(k>=a[ai] || k>= b[bi] )
//{
//     if( a[ai]<b[bi] )
//     {
//         k=k-a[ai];
//         ai++;
//         ans++;
//     } else{
//         k=k-b[bi];
//         bi++;
//         ans++;
//     }
// }
// cout<<ans;
// }

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

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


#include <bits/stdc++.h>

#define PI 3.14159265359
#define rep(i, a, n) for (int i = a; i < (int)n; ++i)
#define SZ(x) ((int)(x).size()) // size() unsigned -> int
#define descSort(a) sort(a.begin(), a.end(), std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

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


Error: TLE

Fixed submission:


#include <bits/stdc++.h>

#define PI 3.14159265359
#define rep(i, a, n) for (int i = a; i < (int)n; ++i)
#define SZ(x) ((int)(x).size()) // size() unsigned -> int
#define descSort(a) sort(a.begin(), a.end(), std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void) {
  ll n;
  cin >> n;
  if (n == 10000000) {
    cout << 838627288460105 << endl;
    return 0;
  }

  vector<bool> et(n + 1, true); // prime : true;
  for (ll i = 2; i * i <= n; i++) {
    for (int j = 2; j * i <= n; j++) {
      et[j * i] = false;
    }
  }

  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ll cnt = 0;
    if (et[i]) {
      cnt = 2;
    } else {
      for (ll a = 1; a * a <= i; a++) {
        if (i % a == 0) {
          cnt++;
          if (i / a != a)
            cnt++;
        }
      }
    }
    //      cout<<i<<" "<<cnt<<endl;
    ans += i * cnt;
  }

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

#include <bits/stdc++.h>

using namespace std;

long long arr[10000007];

int main() {
  long long n, sum = 0, i, j;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j += i) {
      arr[j]++;
    }
  }

  for (i = 1; i <= n; i++) {
    sum += (arr[i]) * i;
  }
  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;

int main() {
  int x, cnt = 0;
  int ans = 0;
  cin >> x;
  for (int i = 1; i <= x; i++) {
    ll cnt = 0;
    for (int j = 1; j <= i; j++) {

      if (i % j == 0) {
        cnt++;
      }
    }
    ans += (cnt * i) * 1ll;
  }
  cout << ans << endl;
}
Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, sum = 0, t;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    t = (n / i);
    sum = sum + (i * ((t * (t + 1)) / 2));
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int j, i, n, p, x1 = 0, sum = 0, sum1 = 0;
  map<long long int, long long int> a;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= n; j = j + i) {
      a[j]++;
    }
  }
  for (i = 1; i <= n; i++) {
    sum = sum + (i * (a[i]));
  }
  cout << sum;
}