alexjercan/bugnet huggingface dataset:
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<int> bits(100);
  int p = 0;
  while (n > 0) {
    bits[p++] = (--n) % 26;
    n /= 26;
  }
  for (int i = p - 1; i >= 0; i--) {
    cout << char(bits[i] + 'a');
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<int> bits(n);
  int p = 0;
  while (n > 0) {
    bits[p++] = (--n) % 26;
    n /= 26;
  }
  for (int i = p - 1; i >= 0; i--) {
    cout << char(bits[i] + 'a');
  }
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

int main() {
  long n;
  std::string s;
  int i;
  s = "abcdefghijklmnopqrstuvwxyz";
  std::string res;
  res = "";
  std::cin >> n;
  while (n > 0) {
    n--;
    i = n % 26;
    n /= 26;
    res = s.at(i) + res;
  }
  std::cout << res;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

int main() {
  long long n;
  std::string s;
  int i;
  s = "abcdefghijklmnopqrstuvwxyz";
  std::string res;
  res = "";
  std::cin >> n;
  while (n > 0) {
    i = n % 26;
    n /= 26;
    res = s.at(i - 1) + res;
  }
  std::cout << res;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

#define rep(i, N) for (int i = 0; i < N; i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

int main(void) {
  ll N;
  cin >> N;

  vector<int> x;

  while (N != 0) {
    x.push_back(N % 26);
    N /= 26;
  }

  string s = "";

  rep(i, (int)x.size() - 1) {
    if (x[i] <= 0) {
      x[i + 1] -= 1;
      x[i] += 26;
    }
    s += (char)('a' + x[i] - 1);
  }
  if (x[x.size() - 1] != 0)
    s += (char)('a' + x[x.size() - 1] - 1);

  for (int i = s.length() - 1; i >= 0; i--) {
    printf("%c", s[i]);
  }
  cout << endl;

  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"

#define rep(i, N) for (int i = 0; i < N; i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

int main(void) {
  ll N;
  cin >> N;
  N--;

  vector<int> x;

  while (N != 0) {
    x.push_back(N % 26);
    N /= 26;
  }

  for (int i = x.size() - 1; i > 0; i--) {
    printf("%c", 'a' + x[i] - 1);
  }
  printf("%c", 'a' + x[0]);
  cout << endl;

  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

string Itoa(ll v, int base) {
  static const char table[] = "abcdefghijklmnopqrstuvwxyz";
  string ret;
  // static numeric_limits<TypeInt> t;
  ll n = v;
  // if (t.is_signed) {
  //	if (v < 0) n *= -1;
  // }
  while (n >= base) {
    ret += table[n % base];
    n /= base;
    --n;
  }
  ret += table[n];
  // if (t.is_signed) {
  //	if (v < 0 && base == 10) ret += '-';
  // }
  //  文字列の順番を逆にする
  reverse(ret.begin(), ret.end());

  return ret;
}

int main(void) {
  ll n;
  cin >> n;
  cout << Itoa(n - 1, 26) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  string s = "aabcdefghijklmnopqrstuvwxyz";
  ll n;
  cin >> n;
  vector<ll> a(n, 0);
  string ans = "";
  rep1(i, (ll)11) {
    ll num = pow(26, 10 - i);
    if (n >= num) {
      ans += s[n / num];
      n %= num;
    }
  }
  cout << ans << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  ll n;
  cin >> n;
  n--;
  vector<char> ans;
  if (n < 26) {
    cout << (char)('a' + ('b' - 'a') * n);
    return 0;
  } else {
    while (n / 26 > 0) {
      ans.push_back((char)('a' + ('b' - 'a') * (n % 26)));
      n = n / 26;
      n--;
    }
    ans.push_back((char)('a' + ('b' - 'a') * (n % 26)));
    reverse(begin(ans), end(ans));
    for (char &e : ans)
      cout << e;
    return 0;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  ll n;
  cin >> n;
  char ans[10] = {};
  int count = 0;
  if (n < 27) {
    ans[0] = 'a' + ('b' - 'a') * n - 1;

  } else {
    for (int i = 10; i > 0; i--) {
      ll a = pow(26, i - 1);
      ll k = n / a;
      if (k != 0) {
        ans[i] = ('a' + ('b' - 'a') * k - 1);
        n = n - a * k;
        count++;
      }
    }
  }
  for (int i = 0; i <= count; i++) {
    cout << ans[count - i];
  }

  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int64_t sum(int64_t x) {
  int64_t S = 0;
  for (int64_t i = 0; i <= x; i++) {
    S += pow(26, i);
  }
  return S;
}

int main() {
  int64_t N;
  cin >> N;
  char C;
  int64_t ccc, keta = 0;
  for (int i = 0; i < 11; i++) {
    if (N >= sum(i) && N < sum(i + 1)) {
      keta = i + 1;
    }
  }
  // cout << keta << endl;

  vector<char> name(keta);
  N -= (sum(keta - 1));

  for (int i = 0; i < keta; i++) {
    ccc = N - N / 26 * 26 + 97;
    N = N / 26;
    C = (char)ccc;
    name.at(i) = C;
  }

  for (int i = keta - 1; i >= 0; i--) {
    cout << name.at(i);
  }
  cout << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int64_t sum(int64_t x) {
  int64_t S = 0;
  for (int64_t i = 0; i <= x; i++) {
    S += pow(26, i);
  }
  return S;
}

int main() {
  int64_t N;
  cin >> N;
  char C;
  int64_t ccc, keta;
  for (int i = 0; i < 10; i++) {
    if (N >= sum(i) && N < sum(i + 1)) {
      keta = i + 1;
    }
  }

  vector<char> name(keta);
  N -= (sum(keta - 1));

  for (int i = 0; i < keta; i++) {
    ccc = N - N / 26 * 26 + 97;
    N = N / 26;
    C = (char)ccc;
    name.at(i) = C;
  }

  for (int i = keta - 1; i >= 0; i--) {
    cout << name.at(i);
  }
  cout << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  int i;
  string ans;
  while (N > 0) {
    ll num = (N - 1) % 26;
    char c = 'a' + num;
    ans = c + ans;
    N = (N - 1) / 26;
  }
  cout << ans << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  int i;
  int t;
  string s = "abcdefghijklmnopqrstuvwxyz";
  while (i < 10) {
    if (N < pow(26, i)) {
      t = i - 1;
      break;
    }
    i++;
  }
  string ans[t];
  int number = N;
  int i2;
  for (int i = t; i >= 0; i--) {
    i2 = number / pow(26, i);
    ans[t - i] = s[i2 - 1];
    cout << ans[t - i];
    number = number - pow(26, i) * i2;
  }
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long n, now = 1, cnt = 26, num = 26;
int main() {
  cin >> n;
  while (cnt < n) {
    num *= 26;
    cnt += num, now++;
  }
  cnt -= num, num /= 26, n -= cnt + 1;
  //	cout<<n<<" "<<num<<"\\n";

  for (int i = 0; i < now; i++) {
    putchar(n / num + 'a');
    n %= num, num /= 26;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
string ans;
int n, now = 1, cnt = 26, num = 26;
int main() {
  cin >> n;
  while (cnt < n) {
    num *= 26;
    cnt += num, now++;
  }
  cnt -= num, num /= 26, n -= cnt + 1;
  //	cout<<n<<" "<<num<<"\\n";

  for (int i = 0; i < now; i++) {
    putchar(n / num + 'a');
    n %= num, num /= 26;
  }
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int _max = 100010;
typedef long long ll;

ll a[1000];
ll x, p = 26;
void solve() {
  int count = 0;
  do {
    a[count++] = (x - 1) % p;
    x = (x - 1) / p;
  } while (x != 0);
  for (int i = count - 1; i >= 0; i--) {
    printf("%c", a[i] + 97);
  }
}

int main() {
  cin >> x;
  solve();
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int _max = 100010;
typedef long long ll;

int a[100];
int x, p = 26;
int solve() {
  int count = 0;
  do {
    a[count++] = x % p;
    x = x / p;
  } while (x != 0);
  for (int i = count - 1; i >= 0; i--) {
    printf("%c", a[i] + 96);
  }
}

int main() {
  cin >> x;
  solve();
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N;
  cin >> N;
  long long a = 1;
  int b = 0;
  string ans = "";
  vector<string> li = {"z", "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"};
  while (true) {
    a = N / 26;
    b = N % 26;
    if (b == 0) {
      a -= 1;
    }
    ans = li.at(b) + ans;
    if (a == 0) {
      break;
    }
    N = a;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  long N;
  cin >> N;
  long a = -1;
  int b = 0;
  string ans = "";
  vector<string> li = {"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"};
  while (a != 0) {
    a = N / 26;
    b = N % 26;
    ans = li.at(b - 1) + ans;
    N = a;
  }
  cout << ans << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
const long long MAX = 1000000000000001;
long long ruijyo(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1)
      res = res * a;
    a = a * a;
    n = n >> 1;
  }
  return res;
}

int main() {
  string alph = "abcdefghijklmnopqrstuvwxyz";
  vector<long long> namesum;
  namesum.push_back(0);
  int i = 0;
  while (namesum.at(i) <= MAX) {
    namesum.push_back(namesum.at(i) * 26 + 26);
    i++;
  }

  long long N;
  cin >> N;
  for (int k = 0; k < namesum.size(); k++) {
    if (namesum.at(k) < N && N <= namesum.at(k + 1)) {
      N = N - namesum.at(k);
      for (int i = k; i >= 0; i--) {
        cout << alph.at((N - 1) / ruijyo(26, i));
        N = N - ((N - 1) / ruijyo(26, i)) * ruijyo(26, i);
      }
      break;
    }
  }
  cout << endl;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
const long long MAX = 1000000000000001;
long long ruijyo(int a, int n) {
  long long res = 1;
  while (n) {
    if (n & 1)
      res = res * a;
    a = a * a;
    n = n >> 1;
  }
  return res;
}

int main() {
  string alph = "abcdefghijklmnopqrstuvwxyz";
  vector<long long> namesum;
  namesum.push_back(0);
  int i = 0;
  while (namesum.at(i) <= MAX) {
    namesum.push_back(namesum.at(i) * 26 + 26);
    i++;
  }

  long long N;
  cin >> N;
  for (int k = 0; k < namesum.size(); k++) {
    if (namesum.at(k) < N && N <= namesum.at(k + 1)) {
      N = N - namesum.at(k);
      for (int i = k; i >= 0; i--) {
        cout << alph.at((N - 1) / ruijyo(26, i));
        N = N - ((N - 1) / ruijyo(26, i)) * ruijyo(26, i);
      }
      break;
    }
  }
  cout << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long pow26(long long n) {
  if (n == 0) {
    return 1;
  } else {
    return 26 * pow26(n - 1);
  }
}

int main() {
  long long n;
  cin >> n;
  n--;
  vector<string> array = {"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"};
  long long c = 1;
  while (n >= pow26(c)) {
    n = n - pow26(c);
    c++;
  }
  string name = "";
  for (long long i = c - 1; i >= 0; i--) {
    int idx = n / pow26(i);
    n = n % pow26(i);
    name += array.at(idx);
  }
  cout << name << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int pow26(int n) {
  if (n == 0) {
    return 1;
  } else {
    return 26 * pow26(n - 1);
  }
}

int main() {
  int n;
  cin >> n;
  n--;
  vector<string> array = {"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 c = 1;
  while (n >= pow26(c)) {
    n = n - pow26(c);
    c++;
  }
  string name = "";
  for (int i = c - 1; i >= 0; i--) {
    int idx = n / pow26(i);
    n = n % pow26(i);
    name += array.at(idx);
  }
  cout << name << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, b, j = 0;
  cin >> n;
  long long i = n;
  char a[50] = {0};
  do {
    b = i % 26;
    i /= 26;
    a[j] = b + 96;
    if (a[j] == 96) {
      a[j] = 122;
      i--;
    }
    j++;
  } while (i != 0);
  for (int c = j - 1; c >= 0; c--) {
    cout << a[c];
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, b, i, j = 0;
  cin >> n;
  char a[50];
  do {
    b = n % 26;
    i = n / 26;
    a[j] = b + 96;
    j++;
  } while (i != 0);
  for (int c = j; c >= 0; c--) {
    cout << a[c];
  }
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  string s = "", t = "zabcdefghijklmnopqrstuvwxyz";
  while (n) {
    s += t.substr((n % 26LL), 1);
    if (n % 26LL) {
      n -= n % 26LL;
    } else {
      n -= 26LL;
    }
    n /= 26LL;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<int> v(n + 10);
  string s = "", t = "a";
  while (n) {
    t[0] = 'a' + n % 26LL - 1;
    n /= 26LL;
    s += t;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>

#define XX first
#define YY second
#define PB push_back
#define MP make_pair

#define NEWLINE cerr << "\\n";
#define HOISE cerr << "hoise " << __LINE__ << "\\n"
#define PAUSE system("pause")
#define DEBUG(x) cerr << #x << " = " << x << "\\n"
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 23;
const ll INFL = 2e18 + 23;

const ll MAX = 1000000000000001;

vector<ll> p;

void print(int len, ll x) {
  if (len == 0)
    return;

  for (int ch = 0; ch < 26; ch++) {
    if (p[len - 1] >= x) {
      cout << (char)('a' + ch);
      print(len - 1, x);
      return;
    }
    x -= p[len - 1];
  }
}

int32_t main() {
  FASTIO;

  p.PB(1);
  while (p.back() <= MAX)
    p.PB(p.back() * 26LL);

  ll n;
  cin >> n;
  int len = 0;
  for (int i = 1; i < p.size(); i++) {
    if (p[i] >= n) {
      len = i;
      break;
    }
    n -= p[i];
  }
  // DEBUG(len);
  // DEBUG(n);
  print(len, n);

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>

#define XX first
#define YY second
#define PB push_back
#define MP make_pair

#define NEWLINE cerr << "\\n";
#define HOISE cerr << "hoise " << __LINE__ << "\\n"
#define PAUSE system("pause")
#define DEBUG(x) cerr << #x << " = " << x << "\\n"
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 23;
const ll INFL = 2e18 + 23;

const ll MAX = 1'000'000'000'000'001;

vector<ll> p;

int32_t main() {
  FASTIO;

  p.PB(1);
  for (int i = 1;; i++)
    if (p.back() * 26 <= MAX)
      p.PB(p.back() * 26);
    else
      break;

  DEBUG(p.size());

  ll n;
  cin >> n;

  int len = 0;
  while (p[len] < n)
    len++;

  for (int i = 1; i < len; i++)
    n -= p[i];

  string ans;
  ans.resize(len, ' ');

  for (int i = 0; i < len; i++) {
    for (int ch = 0; ch < 26; ch++) {
      ll ase = p[len - i - 1];
      // DEBUG(i);
      // DEBUG(ch);
      // DEBUG(ase);
      if (ase >= n) {
        ans[i] = 'a' + ch;
        break;
      } else {
        n -= ase;
      }
    }
  }
  cout << ans;

  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll a = 0, b = 0;
  vector<ll> a2(10000, 0), b2(10000, 0);
  for (ll i = 0; a <= 1000000000000001; i++) {
    if (i - 1 >= 0)
      b += pow(26, i - 1);
    a += pow(26, i);
    if (a > n && b <= n) {
      // cout << n - b << endl ;
      ll m = (n - b);
      for (ll j = i; j >= 1; j--) {
        ll l = pow(26, j - 1);
        // cout << m << ' ' << l << endl ;
        char c = 'a' + m / l;
        cout << c;
        m = m % l;
      }
      return 0;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

vector<ll> ans(1000);
vector<string> S;
void dfs(string s, int i) {
  if (s.size() == i) {
    S.push_back(s);
    return;
  } else {
    for (int j = 97; j <= 122; j++) {
      char t = j;
      string u = s + t;
      dfs(u, i);
    }
  }
}

int main() {
  ll n;
  cin >> n;
  ans.at(0) = 0;
  for (int i = 1; i < 1000; i++) {
    ans.at(i) = ans.at(i - 1) + pow(26, i);
    if (ans.at(i) >= n && ans.at(i - 1) < n) {
      dfs("", i);
      sort(S.begin(), S.end());
      cout << S.at(n - ans.at(i - 1) - 1) << endl;
      return 0;
    }
  }
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N;
  cin >> N;
  string ans = "";

  while (N) {
    N--;
    int tmp = N % 26;
    ans += char('a' + tmp);
    N /= 26;
  }

  reverse(ans.begin(), ans.end());

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
static const int MOD = 1e9 + 7;
static const int INF = 1 << 30;

int main() {
  ll N;
  cin >> N;

  vector<ll> div;
  ll idx = 0;
  ll cur = 1;

  while (cur <= LLONG_MAX) {
    div.push_back(cur);
    cur *= 26;
  }

  idx = div.size() - 1;
  string ans = "";

  while (N > 0) {
    if (div[idx] > N) {
      idx--;
      continue;
    }

    ll tmp = N;
    tmp /= div[idx];
    N -= tmp * div[idx];

    ans += (char)(tmp + 'a' - 1);
    idx--;
  }

  cout << ans << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  string ans = "";
  while (n > 0) {
    int amari = n % 26;
    if (amari == 0)
      ans += 'z', n--;
    else
      ans += (char)amari - 1 + 'a';
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  string ans = "";
  n--;
  while (n > 0) {
    int amari = n % 26;
    ans += (char)amari + 'a';
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < ans.size() - 1; ++i) {
    cout << char(ans[i] - 1);
  }
  cout << ans[ans.size() - 1] << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <vector>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll N;
  cin >> N;
  ll n = -1;
  ll cnt = 1;
  rep(i, 1000) {
    n += pow(26, i);
    if (N > n) {
    } else {
      cnt = i;
      break;
    }
  }
  n = N;
  ll p = 0;
  string out = "";
  rep(i, cnt) {
    p = n % 26;
    if (p == 0)
      p = 26;
    char add = 'a' + p - 1;
    out = add + out;
    n = (n - p) / 26;
  }
  cout << out << endl;
  return 0;
}


Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <vector>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll N;
  cin >> N;
  ll n = -1;
  ll cnt = 1;
  rep(i, 1000) {
    n += pow(26, i);
    if (N > n) {
    } else {
      cnt = i;
      break;
    }
  }
  n = N;
  ll p = 0;
  string out = "";
  rep(i, cnt) {
    p = n % 26;
    if (p > 26)
      p = 26;
    if (p == 0) {
      out[out.length() - 1] -= 1;
      p = 26;
    }
    if (p == 26 && n - p * pow(26, cnt - i - 1) < 0)
      p = 25;
    char add = 'a' + p - 1;
    out = add + out;
    n = (n - p) / 26;
  }
  cout << out << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t n;
  string alf, ans;
  alf = "abcdefghijklmnopqrstuvwxyz";
  cin >> n;
  while (n > 0) {
    ans = alf.at((n - 1) % 26) + ans;
    n = (n - 1) / 26;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  string alf, ans;
  alf = "abcdefghijklmnopqrstuvwxyz";
  cin >> n;
  while (n > 0) {
    ans = alf.at(n % 26 - 1) + ans;
    n = n / 26;
  }
  cout << ans << endl;
}