Problem p02624 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ss string
#define ll long long int
#define Endl endl
#define u_b upper_bound
#define rep(i, n) for (int i = 0; i < n; i++)
#define ld long double
#define tc                                                                     \\
  long long t;                                                                 \\
  cin >> t;                                                                    \\
  while (t--)
#define fr(i, a, b) for (long long int i = a; i <= b; i++)
#define E endl
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define V deque<ll> v;
#define aaste                                                                  \\
  long long int n;                                                             \\
  cin >> n;                                                                    \\
  long long int a[n];                                                          \\
  for (long long int i = 0; i < n; i++)                                        \\
    cin >> a[i];
const ll mod = 1000000007;
const ll MOD1 = (int)1e9 + 9;
const ll MOD2 = 998244353;
const ld pi = atan2(0, -1);
const ld eps = 1e-9;
const int N = 2e5 + 5;

const int MAXR = 1000005;
ll tests = 1;

using namespace std;
ll binarySearch(ll l, ll r, ll k) {
  if (r >= l) {
    ll mid = l + (r - l) / 2;
    if (mid * (mid + 1) == k)
      return 1;
    if (mid * (mid + 1) > k)
      return binarySearch(l, mid - 1, k);
    return binarySearch(mid + 1, r, k);
  }
  return 0;
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
void swap(ll *p1, ll *p2) {
  ll temp = *p1;
  *p1 = *p2;
  *p2 = temp;
}
ll cbratt(ll x) {
  ll l = 0, r = MAXR;
  while (l != r) {
    ll m = (l + r + 1) / 2;
    if (m * m * m > x)
      r = m - 1;
    else
      l = m;
  }
  return l;
}
int MaxSubArraySumReturn(int a[], int n) // negative thakle o kaaj korbe in O(n)
{

  int sum = 0, best = 0;
  for (ll i = 0; i < n; i++) {
    sum = max(a[i], a[i] + sum);
    best = max(best, sum);
  }
  return best;
}
ll totalDigits(ll n) {

  ll number_of_digits = 0;
  for (ll i = 1; i <= n; i *= 10)
    number_of_digits += (n - i + 1);

  return number_of_digits;
}
// Functions
ll a[10000001];
void findDivisors(ll n) {

  // Array to store the count
  // of divisors
  ll divi[n + 1];
  memset(divi, 0, sizeof divi);
  // For every number from 1 to n
  for (ll i = 1; i <= n; i++) {

    // Increase divisors count for
    // every number divisible by i
    for (ll j = 1; j * i <= n; j++)
      divi[i * j]++;
  }
  for (ll i = 1; i <= n; i++)
    a[i] = divi[i];
}
int main() {
#ifndef ONLINE_JUDGE
  {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
  }
#endif
  ll n;
  cin >> n;
  findDivisors(n);
  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    sum += (i * a[i]);
  }
  cout << sum << Endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ss string
#define ll long long int
#define Endl endl
#define u_b upper_bound
#define rep(i, n) for (int i = 0; i < n; i++)
#define ld long double
#define tc                                                                     \\
  long long t;                                                                 \\
  cin >> t;                                                                    \\
  while (t--)
#define fr(i, a, b) for (long long int i = a; i <= b; i++)
#define E endl
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define V deque<ll> v;
#define aaste                                                                  \\
  long long int n;                                                             \\
  cin >> n;                                                                    \\
  long long int a[n];                                                          \\
  for (long long int i = 0; i < n; i++)                                        \\
    cin >> a[i];
const ll mod = 1000000007;
const ll MOD1 = (int)1e9 + 9;
const ll MOD2 = 998244353;
const ld pi = atan2(0, -1);
const ld eps = 1e-9;
const int N = 2e5 + 5;

const int MAXR = 1000005;
ll tests = 1;

using namespace std;
ll binarySearch(ll l, ll r, ll k) {
  if (r >= l) {
    ll mid = l + (r - l) / 2;
    if (mid * (mid + 1) == k)
      return 1;
    if (mid * (mid + 1) > k)
      return binarySearch(l, mid - 1, k);
    return binarySearch(mid + 1, r, k);
  }
  return 0;
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
void swap(ll *p1, ll *p2) {
  ll temp = *p1;
  *p1 = *p2;
  *p2 = temp;
}
ll cbratt(ll x) {
  ll l = 0, r = MAXR;
  while (l != r) {
    ll m = (l + r + 1) / 2;
    if (m * m * m > x)
      r = m - 1;
    else
      l = m;
  }
  return l;
}
int MaxSubArraySumReturn(int a[], int n) // negative thakle o kaaj korbe in O(n)
{

  int sum = 0, best = 0;
  for (ll i = 0; i < n; i++) {
    sum = max(a[i], a[i] + sum);
    best = max(best, sum);
  }
  return best;
}
ll totalDigits(ll n) {

  ll number_of_digits = 0;
  for (ll i = 1; i <= n; i *= 10)
    number_of_digits += (n - i + 1);

  return number_of_digits;
}
// Functions
ll a[1000000];
void findDivisors(ll n) {

  // Array to store the count
  // of divisors
  ll divi[n + 1];
  memset(divi, 0, sizeof divi);
  // For every number from 1 to n
  for (ll i = 1; i <= n; i++) {

    // Increase divisors count for
    // every number divisible by i
    for (ll j = 1; j * i <= n; j++)
      divi[i * j]++;
  }
  for (ll i = 1; i <= n; i++)
    a[i] = divi[i];
}
int main() {
#ifndef ONLINE_JUDGE
  {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
  }
#endif
  ll n;
  cin >> n;
  findDivisors(n);
  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    sum += (i * a[i]);
  }
  cout << sum << Endl;
}