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

/// Coded by Dhiman Sarker Bappi (Dhimanda) - RMSTU

#include <bits/stdc++.h>
using namespace std;
#define in_file freopen("input.txt", "r", stdin)
#define out_file freopen("output.txt", "w", stdout)
#define fast ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define pb push_back
#define popb pop_back
#define pf push_front
#define popf pop_front
#define lcm(a, b) (a * b) / gcd(a, b)
#define gcd(a, b) __gcd(a, b)
#define pi 2 * acos(0)
#define elif else if
#define ll long long
#define nl '\\n'
#define endl '\\n'
#define fori(i, b, e) for (int(i) = (b); (i) <= (e); (i)++)
#define for0(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define sp fixed << setprecision
#define all(x) x.begin(), x.end()

// ===================== DEBUG  ==========================

vector<string> vec_spltr(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty())
    res.push_back(s.substr(0, s.find(','))), s = s.substr(s.find(',') + 1);
  return res;
}
void dbg_out(vector<string> __attribute__((unused)) args,
             __attribute__((unused)) int idx,
             __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  dbg_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) dbg_out(vec_spltr(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)

// ===================== custom function ==========================
ll pow_mod(ll nn, ll pp, ll mm) {
  ll res = 1;
  while (pp > 0) {
    if (pp & 1)
      res = (res * nn) % mm;
    pp = pp >> 1;
    nn = (nn * nn) % mm;
  }
  return res;
}
void dhimanda();
// ===================== Main function ==========================
int main() {
  // in_file;
  // out_file;
  int t = 1;
  // cin >> t;
  fori(i, 1, t) {
    // printf("Case %d: ", i);
    dhimanda();
  }
  // main();
  return 0;
}
void dhimanda() {
  ll n;
  cin >> n;
  string a = "0abcdefghijklmnopqrstuvwxyz";
  string ans = "";
  while (n) {
    ll x = n % 26;
    if (x == 0)
      x = 26;
    ans += a[x];
    debug(x, ans, n);
    n /= 26;
    if (x == 26)
      n--;
  }
  reverse(all(ans));
  cout << ans << endl;
}

// Contact : chessdhiman@gmail.com


Error: TLE

Fixed submission:

/// Coded by Dhiman Sarker Bappi (Dhimanda) - RMSTU

#include <bits/stdc++.h>
using namespace std;
#define in_file freopen("input.txt", "r", stdin)
#define out_file freopen("output.txt", "w", stdout)
#define fast ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define pb push_back
#define popb pop_back
#define pf push_front
#define popf pop_front
#define lcm(a, b) (a * b) / gcd(a, b)
#define gcd(a, b) __gcd(a, b)
#define pi 2 * acos(0)
#define elif else if
#define ll long long
#define nl '\\n'
#define endl '\\n'
#define fori(i, b, e) for (int(i) = (b); (i) <= (e); (i)++)
#define for0(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define sp fixed << setprecision
#define all(x) x.begin(), x.end()

// ===================== DEBUG  ==========================

vector<string> vec_spltr(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty())
    res.push_back(s.substr(0, s.find(','))), s = s.substr(s.find(',') + 1);
  return res;
}
void dbg_out(vector<string> __attribute__((unused)) args,
             __attribute__((unused)) int idx,
             __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  dbg_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) dbg_out(vec_spltr(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)

// ===================== custom function ==========================
ll pow_mod(ll nn, ll pp, ll mm) {
  ll res = 1;
  while (pp > 0) {
    if (pp & 1)
      res = (res * nn) % mm;
    pp = pp >> 1;
    nn = (nn * nn) % mm;
  }
  return res;
}
void dhimanda();
// ===================== Main function ==========================
int main() {
  // in_file;
  // out_file;
  int t = 1;
  // cin >> t;
  fori(i, 1, t) {
    // printf("Case %d: ", i);
    dhimanda();
  }
  main();
  return 0;
}
void dhimanda() {
  ll n;
  cin >> n;
  string a = "0abcdefghijklmnopqrstuvwxyz";
  string ans = "";
  while (n) {
    ll x = n % 26;
    if (x == 0)
      x = 26;
    ans += a[x];
    debug(x, ans, n);
    n /= 26;
    if (x == 26)
      n--;
  }
  reverse(all(ans));
  cout << ans << endl;
}

// Contact : chessdhiman@gmail.com