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

/*
            _           __                _      _____ _____ _____
  ___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
 / __| | | | '_ \\ / _ \\ |_| '__/ _ \\/ _` | |/ /    / /   / /   / /
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /
 \\___|\\__,_|_.__/ \\___|_| |_|  \\___|\\__,_|_|\\_\\  /_/   /_/   /_/

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<int> vl;
typedef vector<pll> vpll;
typedef unordered_map<ll, ll> umap;
// #pragma GCC optimize "trapv"
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define For(i, n) for (int i = 0; i < (ll)n; i++)
#define Rev(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, n) for (int i = 1; i <= n; ++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(), (v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a, b) make_pair(a, b)
#define pf(n)                                                                  \\
  {                                                                            \\
    cout << n << "\\n";                                                         \\
    return;                                                                    \\
  }
#define po(n) cout << n << "\\n "
#define pff(n) cout << n << " ";
#define ar array
#define endl "\\n"
#define PI acos(-1)
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
// #ifndef ONLINE_JUDGE
// #ifndef LOCAL
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
// #else
// #define debug(x...)
// #endif
#define int ll
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long const M = 1e9 + 7;
const long mxN = 1e5 + 2;
const ll INF = 1e18;
string X = "abcdefghijklmnopqrstuvwxyz";
ll x = 26ll;
ll P(ll b, ll p) {
  ll r = 1;
  for (; p; p /= 2ll, b = b * b)
    if (p & 1ll)
      r = b * r;
  return r;
}
void solve() {
  ll n;
  cin >> n;
  ll s = 0ll, c = 1ll;
  for (;;) {
    if (s + P(x, c) >= n)
      break;
    s += P(x, c);
    c++;
  }
  n -= s;
  string ans = "";
  while (c > 0) {
    int v = P(x, c - 1ll);
    ll k = (n + v - 1ll) / v;
    ans += X[k - 1ll];
    --c;
    n -= v * (k - 1ll);
    // debug(c,n) ;
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // cout << setprecision(20) << fixed ;
  solve();
  // ll t ; cin >> t ; while(t--)solve() ;
  return 0;
}


Error: 0

Fixed submission:

/*
            _           __                _      _____ _____ _____
  ___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
 / __| | | | '_ \\ / _ \\ |_| '__/ _ \\/ _` | |/ /    / /   / /   / /
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /
 \\___|\\__,_|_.__/ \\___|_| |_|  \\___|\\__,_|_|\\_\\  /_/   /_/   /_/

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<int> vl;
typedef vector<pll> vpll;
typedef unordered_map<ll, ll> umap;
// #pragma GCC optimize "trapv"
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define For(i, n) for (int i = 0; i < (ll)n; i++)
#define Rev(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, n) for (int i = 1; i <= n; ++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(), (v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a, b) make_pair(a, b)
#define pf(n)                                                                  \\
  {                                                                            \\
    cout << n << "\\n";                                                         \\
    return;                                                                    \\
  }
#define po(n) cout << n << "\\n "
#define pff(n) cout << n << " ";
#define ar array
#define endl "\\n"
#define PI acos(-1)
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
// #ifndef ONLINE_JUDGE
// #ifndef LOCAL
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
// #else
// #define debug(x...)
// #endif
// #define int ll
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long const M = 1e9 + 7;
const long mxN = 1e5 + 2;
const ll INF = 1e18;
string X = "abcdefghijklmnopqrstuvwxyz";
ll x = 26;
ll P(ll b, ll p) {
  ll r = 1;
  for (; p; p /= 2, b = b * b)
    if (p & 1)
      r = b * r;
  return r;
}
char eval(ll n, ll c) {}
void solve() {
  ll n;
  cin >> n;
  ll s = 0, c = 1;
  for (;;) {
    if (s + P(x, c) >= n)
      break;
    s += P(x, c);
    c++;
  }
  n -= s;

  string ans = "";
  while (c > 0) {
    int v = P(x, c - 1);
    ll k = (n + v - 1) / v;
    ans += X[k - 1];
    --c;
    n -= v * (k - 1);
    // debug(c,n) ;
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // cout << setprecision(20) << fixed ;
  solve();
  // ll t ; cin >> t ; while(t--)solve() ;
  return 0;
}