Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define FORLE(start, end, leap) for (int i(start); i <= end; i += leap)
#define FORL(start, end, leap) for (int i(start); i < end; i += leap)
#define FORGE(start, end, leap) for (int i(start); i >= end; i -= leap)
#define FORG(start, end, leap) for (int i(start); i > end; i -= leap)
#define lowbit(x) (x & (-x))
namespace BST { // Basic formulas
#define ll long long
inline ll QuickPower(ll x, ll y, ll mod) // 快速幂
{
  ll res = 1;
  while (y) {
    if (y & 1)
      res = res * x % mod;
    y >>= 1;
    x = (x * x) % mod;
  }
  return res;
}
#undef ll
template <typename T> inline void read(T &t) {
  t = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    t = (t << 3) + (t << 1) + c - '0';
    c = getchar();
  }
  t *= f;
}
template <typename T, typename... Args> inline void read(T &t, Args &...args) {
  read(t);
  read(args...);
}
template <typename T> inline void put(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x > 9)
    put(x / 10);
  putchar(x % 10 + '0');
}
template <typename T, typename... Args> inline void put(T &t, Args &...args) {
  put(t);
  putchar(' ');
  put(args...);
}
}; // namespace BST
using namespace BST;
int main(void) {
  long long N;
  string str;
  read(N);
  while (N >= 1) {
    if (N % 26 == 0) {
      str.push_back('z'), N /= 26, N -= 1;
      continue;
    }
    str.push_back(N % 26 + 'a' - 1);
    N /= 26;
  }
  reverse(str.begin(), str.end());
  cout << str;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FORLE(start, end, leap) for (int i(start); i <= end; i += leap)
#define FORL(start, end, leap) for (int i(start); i < end; i += leap)
#define FORGE(start, end, leap) for (int i(start); i >= end; i -= leap)
#define FORG(start, end, leap) for (int i(start); i > end; i -= leap)
#define lowbit(x) (x & (-x))
namespace BST { // Basic formulas
#define ll long long
inline ll QuickPower(ll x, ll y, ll mod) // 快速幂
{
  ll res = 1;
  while (y) {
    if (y & 1)
      res = res * x % mod;
    y >>= 1;
    x = (x * x) % mod;
  }
  return res;
}
#undef ll
template <typename T> inline void read(T &t) {
  t = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    t = (t << 3) + (t << 1) + c - '0';
    c = getchar();
  }
  t *= f;
}
template <typename T, typename... Args> inline void read(T &t, Args &...args) {
  read(t);
  read(args...);
}
template <typename T> inline void put(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x > 9)
    put(x / 10);
  putchar(x % 10 + '0');
}
template <typename T, typename... Args> inline void put(T &t, Args &...args) {
  put(t);
  putchar(' ');
  put(args...);
}
};              // namespace BST
namespace BIT { // Binary Indexed Tree
#define MAXN ((int)1e5)
int a[MAXN], c[MAXN];
inline int ask(int x) { // Ask the sum of a[1] ~ a[x]
  int ans = 0;
  while (x) {
    ans += c[x];
    x -= lowbit(x);
  }
  return ans;
}
inline void update(int x, int val) // add val to a[x]
{
  while (x <= MAXN) {
    c[x] += val;
    x += lowbit(x);
  }
}
#undef MAXN
};               // namespace BIT
namespace SEGT { // Segment Tree
#define MAXN ((int)1e6)
#define ll long long
#define ls(x) x << 1
#define rs(x) x << 1 | 1
unsigned long long a[MAXN], ans[MAXN << 2], tag[MAXN << 2];
inline void push_up(ll p) { ans[p] = ans[ls(p)] + ans[rs(p)]; }
void build(ll p, ll l, ll r) {
  tag[p] = 0;
  if (l == r) {
    ans[p] = a[l];
    return;
  }
  ll mid = (l + r) >> 1;
  build(ls(p), l, mid);
  build(rs(p), mid + 1, r);
  push_up(p);
}
inline void f(ll p, ll l, ll r, ll k) {
  tag[p] = tag[p] + k;
  ans[p] = ans[p] + k * (r - l + 1);
}
inline void push_down(ll p, ll l, ll r) {
  ll mid = (l + r) >> 1;
  f(ls(p), l, mid, tag[p]);
  f(rs(p), mid + 1, r, tag[p]);
  tag[p] = 0;
}
inline void update(ll nl, ll nr, ll l, ll r, ll p, ll k) {
  if (nl <= l && r <= nr) {
    ans[p] += k * (r - l + 1);
    tag[p] += k;
    return;
  }
  push_down(p, l, r);
  ll mid = (l + r) >> 1;
  if (nl <= mid)
    update(nl, nr, l, mid, ls(p), k);
  if (nr > mid)
    update(nl, nr, mid + 1, r, rs(p), k);
  push_up(p);
}
ll query(ll q_x, ll q_y, ll l, ll r, ll p) {
  ll res = 0;
  if (q_x <= l && r <= q_y)
    return ans[p];
  ll mid = (l + r) >> 1;
  push_down(p, l, r);
  if (q_x <= mid)
    res += query(q_x, q_y, l, mid, ls(p));
  if (q_y > mid)
    res += query(q_x, q_y, mid + 1, r, rs(p));
  return res;
}
#undef MAXN
#undef ll
#undef rs
#undef ls
}; // namespace SEGT
using namespace BST;
char alph[27] = {'1', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
                 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
                 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int main(void) {
  int N;
  vector<char> str;
  read(N);
  int digit = 0;
  while (N >= 1) {
    str.push_back(alph[N % 26]);
    N /= 26;
    digit++;
  }
  reverse(str.begin(), str.end());
  for (int i = 0; i <= digit; i++)
    putchar(str[i]);
  return 0;
}