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

// is there any case of -1 or any special corner cases ?
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int, int>
#define all(v) v.begin(), v.end()
#define zeros(arr) memset(arr, 0, sizeof(arr));
#define precise(num)                                                           \\
  cout << fixed;                                                               \\
  cout << std::setprecision(num)
#define nl cout << "\\n";
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
const int maxx = 3 * 1e5, limit = 9 * 1e18, MOD = 1e9 + 7;
#define boost                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n';
int32_t main() {
  boost;
  int n;
  cin >> n;

  int prime[n + 2];
  zeros(prime);
  for (int i = 2; i <= n; i++) {
    if (prime[i] == 0) {
      prime[i] = i;
      for (int j = i * i; j <= n; j = j + i) {
        prime[j] = i;
      }
    }
  }
  // for(int)

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

    int num = n - i;
    // map<int,int>cn;
    int res = 1;
    while (num > 1) {
      int cp = 0;
      int p1 = prime[num];
      // cout<<num<<" "<<p1<<endl;
      while (num > 1 && num % p1 == 0) {
        num /= p1;
        // cout<<num<<" "<<p1<<endl;
        cp++;
      }
      res = res * (cp + 1);
    }

    ans = ans + res;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

// is there any case of -1 or any special corner cases ?
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int, int>
#define all(v) v.begin(), v.end()
#define zeros(arr) memset(arr, 0, sizeof(arr));
#define precise(num)                                                           \\
  cout << fixed;                                                               \\
  cout << std::setprecision(num)
#define nl cout << "\\n";
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
const int maxx = 3 * 1e5, limit = 9 * 1e18, MOD = 1e9 + 7;
#define boost                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n';
int32_t main() {
  boost;
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= 1e6; i++) {

    int num = n - i;
    for (int j = 1; j * j <= num; j++) {
      if (num % j == 0) {
        ans += 2;
        if (num / j == j)
          ans--;
      }
    }
  }
  cout << ans << endl;
}