Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):


///***###                               بسم الله الرحمن الرحيم ###***///

/*
                    Author          : Borhan Uddin Rafi
                    University      : Begum Rokeya University,Rangpur.
                    Date            : 27 June,2020;
*/

///************************Start Of Template*************************///

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#define Read_Fast                                                              \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(), a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i, n) for (i = 0; i < n; i++)
#define f1(i, n) for (i = 1; i < n; i++)
#define f1n(i, n) for (i = 1; i <= n; i++)
#define szf sizeof()
#define sz size()
#define ln length()
#define mem(x, r) memset(x, r, sizeof(x))
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
string str, ans, rafi, chk;

map<string, string> maap;
queue<int> q;

/*** this solution will not work in terminal because of freopen................
    If you close that freopen then its work here.
    But before submission you need to open freopen line ***/

//////return sum of all digits///////

map<ll, ll> arr;

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  Read_Fast;
  int t;
  // cin>>t;
  //  while(t--)
  //  {
  ll n, m, i, j, cnt1 = 0, cnt2 = 0, cnt = 0, even = 0, odd = 0, len, k, r, l,
                 z = 0, x = 0, y = 0, flag = 0, sum = 0;
  ll a = 0, b = 0, c = 0, d, ans = 0, zero = 0, fst = 0, snd = 0, lst = 0,
     one = 0, mn = INT_MAX, mx = INT_MIN;
  char ch;
  int h1, h2, m1, m2, h, time;
  string str, store = "";
  cin >> n;
  // map<ll,ll>arr;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j = j + i) {
      arr[j]++;
    }
  }
  for (ll i = 1; i <= n; i++) {
    sum = sum + (i * arr[i]);
  }
  cout << sum << endl;

  // }
  return 0;
  ///***###            ٱلْحَمْدُ لِلَّٰهِ          ###***///
}


Fixed submission:


///***###                               بسم الله الرحمن الرحيم ###***///

/*
                    Author          : Borhan Uddin Rafi
                    University      : Begum Rokeya University,Rangpur.
                    Date            : 27 June,2020;
*/

///************************Start Of Template*************************///

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#define Read_Fast                                                              \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(), a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i, n) for (i = 0; i < n; i++)
#define f1(i, n) for (i = 1; i < n; i++)
#define f1n(i, n) for (i = 1; i <= n; i++)
#define szf sizeof()
#define sz size()
#define ln length()
#define mem(x, r) memset(x, r, sizeof(x))
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
string str, ans, rafi, chk;

map<string, string> maap;
queue<int> q;

/*** this solution will not work in terminal because of freopen................
    If you close that freopen then its work here.
    But before submission you need to open freopen line ***/

//////return sum of all digits///////

int arr[10000004];

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  Read_Fast;
  int t;
  // cin>>t;
  //  while(t--)
  //  {
  ll n, m, i, j, cnt1 = 0, cnt2 = 0, cnt = 0, even = 0, odd = 0, len, k, r, l,
                 z = 0, x = 0, y = 0, flag = 0, sum = 0;
  ll a = 0, b = 0, c = 0, d, ans = 0, zero = 0, fst = 0, snd = 0, lst = 0,
     one = 0, mn = INT_MAX, mx = INT_MIN;
  char ch;
  int h1, h2, m1, m2, h, time;
  string str, store = "";
  cin >> n;
  // map<ll,ll>arr;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j = j + i) {
      arr[j]++;
    }
  }
  for (ll i = 1; i <= n; i++) {
    sum = sum + (i * arr[i]);
  }
  cout << sum << endl;

  // }
  return 0;
  ///***###            ٱلْحَمْدُ لِلَّٰهِ          ###***///
}