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

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll unsigned long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define pci pair < char, int
#define mii map<int, int>
#define mll map<long long int, long long int>
#define mci map<char, int>
#define umii unordered_map<int, int>
#define umll unordered_map<long long int, long long int>
#define umci unordered_map<char, int>
#define F first
#define S second
#define pb push_back
#define endl '\\n'
#define mod 1000000007
using namespace std;
#define maxval 10003000
ll power(ll x, ll n) { // ll x1=0;
  ll result = 1;
  while (n > 0) {
    if (n % 2 == 1)
      result = (result * x);
    //  if(result>=1000000001) return 0;
    x = (x * x);
    //   if(x>=1000000001) return 0;
    n = n / 2;
  }
  return result;
}
int vowel(char x) {
  if (x == 'a')
    return 1;
  if (x == 'e')
    return 1;
  if (x == 'i')
    return 1;
  if (x == 'o')
    return 1;
  if (x == 'u')
    return 1;
  return 0;
}
ll numb(ll x) {
  ll z = sqrt(x);
  if (z * z == x)
    return 1;
  return 0;
}
int main() {
  IOS;
  ll t;
  t = 1; // cin>>t;

  while (t--) {
    ll n;
    cin >> n;
    ll ans = 0;
    ll v = 0;
    for (ll i = 1; i < n; i++) {
      //  if(numb(i)) v++;
      ans = ans + (n - 1) / i;
    }
    cout << ans - v << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll unsigned long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define pci pair < char, int
#define mii map<int, int>
#define mll map<long long int, long long int>
#define mci map<char, int>
#define umii unordered_map<int, int>
#define umll unordered_map<long long int, long long int>
#define umci unordered_map<char, int>
#define F first
#define S second
#define pb push_back
#define endl '\\n'
#define mod 1000000007
using namespace std;
#define maxval 10003000
ll power(ll x, ll n) {
  ll x1 = 0;
  ll result = 1;
  while (n > 0) {
    if (n % 2 == 1)
      result = (result * x);
    //  if(result>=1000000001) return 0;
    x = (x * x);
    //   if(x>=1000000001) return 0;
    n = n / 2;
  }
  return result;
}
int vowel(char x) {
  if (x == 'a')
    return 1;
  if (x == 'e')
    return 1;
  if (x == 'i')
    return 1;
  if (x == 'o')
    return 1;
  if (x == 'u')
    return 1;
  return 0;
}
ll numb(ll x) {
  ll z = 0;
  for (ll i = 1; i <= sqrt(x); i++) {

    if (x % i == 0) {
      if (i != sqrt(x))
        z = z + 2;
      else
        z++;
    }
  }
  return z;
}
int main() {
  IOS;
  ll t;
  t = 1; // cin>>t;

  while (t--) {
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i < n; i++) {
      ans = ans + numb(n - i);
    }
    cout << ans << "\\n";
  }

  return 0;
}