Problem p02624 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\\n"
#define EM empty()
#define RB rbegin()
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define MD 1000000007
#define PPF pop_front()
#define LL long long int
#define PQ priority_queue
#define N cout << "NO" << endl
#define Y cout << "YES" << endl
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define file                                                                   \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout)
#define UOSMOY                                                                 \\
  v.C;                                                                         \\
  w.C;                                                                         \\
  ww.C;                                                                        \\
  u.C;                                                                         \\
  uu.C;                                                                        \\
  uo.C;                                                                        \\
  vo.C;                                                                        \\
  vu.C;                                                                        \\
  ab.C;                                                                        \\
  bc.C;                                                                        \\
  cc.C;                                                                        \\
  uuu.C;                                                                       \\
  a.C;                                                                         \\
  b.C;                                                                         \\
  c.C
V<LL> v;
V<LL> w, ab, bc;
set<LL> uo;
map<LL, LL> u, uc;
map<LL, LL> ww, cc;
LL ar[120005];
LL br[500005];
LL cr[500][500];
V<pair<LL, LL>> uu;
map<LL, V<LL>> uuu;
map<pair<LL, LL>, LL> vo;
map<pair<LL, LL>, LL> vu;
LL vv[20000001];
void veve(LL n) {
  LL i, j;
  for (i = 1; i <= n; i++) {
    if (i % 2 == 1) {
      vv[i] = i;
    } else {
      vv[i] = 2;
    }
  }
  for (i = 3; i <= sqrt(n); i += 2) {
    if (vv[i] == i) {
      for (j = i * i; j <= n; j += 2 * i) {
        if (vv[j] == j) {
          vv[j] = i;
        }
      }
    }
  }
}
int main() {
  //  BRR;
  //  file;
  FAST;
  char ch;
  string a, b, c, str;
  DL x, y, d, e, f, g, h;
  LL n, m, i, j, k, p, q, o, l, s, tt = 1, t, z, aa, r = 0;
  //    cin>>tt;
  veve(10000000);
  while (tt--) {
    UOSMOY;
    cin >> n;
    k = 0;
    for (i = 1; i <= n; i++) {
      if (i == 1) {
        k += 1;
        continue;
      }
      j = i;
      l = 1;
      while (j != 1) {
        u[vv[j]]++;
        j /= vv[j];
      }
      for (auto it = u.B; it != u.E; it++) {
        l *= (it->SE + 1);
      }
      k += (l * i);
      u.C;
      //            cout<<k<<endl;
    }
    cout << k << 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() {
  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;
}