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

#include <bits/stdc++.h>

#define ll long long

#define ull unsigned long long

#define pii pair<int, int>

#define pll pair<ll int, ll int>

#define ff first

#define ss second

#define pb push_back

#define eb emplace_back

#define debug(n) cout << "DEBUG1 " << n << "\\n";

#define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\\n";

#define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\\n";

#define debug4(n, m, x, y)                                                     \\
  cout << "DEBUG4 " << n << ' ' << m << ' ' << x << ' ' << y << "\\n";

#define ss_def                                                                 \\
  stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int)

#define upzero(n)                                                              \\
  if (n < 0)                                                                   \\
  n = 0

#define alive(n) cout << "Alive here: checkpoint " << n << endl

#pragma GCC optimize("Ofast")

using namespace std;

void yes() {

  cout << "YES\\n";

  return;
}

void no() {

  cout << "NO\\n";

  return;
}

void init() {

  // initialize
}

int pp(int n) {

  int cnt = 0;

  for (int i = 1; i < ceil(sqrt(n)); i++) {

    if (n % i == 0)
      cnt += 2;
  }

  if (floor(sqrt(n)) * floor(sqrt(n)) == n)
    cnt++;

  return cnt;
}

void solve(int case_no) {

  // implementation

  int n;

  cin >> n;

  int cnt[n + 1] = {0};

  ll int ans = 0;

  for (int i = 1; i <= n; i++) {

    for (int j = i; j <= n; j += i) {

      cnt[j]++;
    }
  }

  for (int i = 1; i < n; i++)
    ans += cnt[i];

  cout << ans << endl;
}

int main() {

  ios::sync_with_stdio(false);

  cin.tie(NULL);

  cout.tie(NULL);

  srand(time(NULL));

  init();

  int t = 1;

  //    cin >> t;

  for (int i = 1; i <= t; i++)
    solve(i);
}

/*

*/

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define ll long long

#define ull unsigned long long

#define pii pair<int, int>

#define pll pair<ll int, ll int>

#define ff first

#define ss second

#define pb push_back

#define eb emplace_back

#define debug(n) cout << "DEBUG1 " << n << "\\n";

#define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\\n";

#define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\\n";

#define debug4(n, m, x, y)                                                     \\
  cout << "DEBUG4 " << n << ' ' << m << ' ' << x << ' ' << y << "\\n";

#define ss_def                                                                 \\
  stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int)

#define upzero(n)                                                              \\
  if (n < 0)                                                                   \\
  n = 0

#define alive(n) cout << "Alive here: checkpoint " << n << endl

#pragma GCC optimize("Ofast")

using namespace std;

void yes() {

  cout << "YES\\n";

  return;
}

void no() {

  cout << "NO\\n";

  return;
}

void init() {

  // initialize
}

int pp(int n) {

  int cnt = 0;

  for (int i = 1; i < ceil(sqrt(n)); i++) {

    if (n % i == 0)
      cnt += 2;
  }

  if (floor(sqrt(n)) * floor(sqrt(n)) == n)
    cnt++;

  return cnt;
}

void solve(int case_no) {

  // implementation

  int n;

  cin >> n;

  ll int ans = 0;

  for (int i = 1; i < n; i++) {

    ans += pp(i);
  }

  cout << ans << endl;
}

int main() {

  ios::sync_with_stdio(false);

  cin.tie(NULL);

  cout.tie(NULL);

  srand(time(NULL));

  init();

  int t = 1;

  //    cin >> t;

  for (int i = 1; i <= t; i++)
    solve(i);
}

/*

*/