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

#include <bits/stdc++.h>

using namespace std;

int main(void) {

#define int long long

  long long N;
  cin >> N;
  vector<char> A = {'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'};

  string ans;
  if (N <= 26) {
    ans = A.at(N - 1);
  } else if (N <= 702) { // 26 * 26 + 26
    int n = N - 27;
    int f = n / 26;
    int s = n % 26;
    ans.push_back(A.at(f));
    ans.push_back(A.at(s));
  } else if (N <= 18278) { // 26 * 26 * 26 + 702
    int n = N - 703;       // n = 0 ~ 17575
    int q1 = n / (26 * 26);
    int r1 = n % (26 * 26);
    int q2 = r1 / (26);
    int r2 = r1 % (26);
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(r2));
  } else if (N <= 475254) { // 26 * 26 * 26 * 26 + 18278
    int n = N - 18279;
    int q1 = n / (26 * 26 * 26);
    int r1 = n % (26 * 26 * 26);
    int q2 = r1 / (26 * 26);
    int r2 = r1 % (26 * 26);
    int q3 = r2 / 26;
    int r3 = r2 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(r3));
  } else if (N <= 12356630) { // 26 * 26 * 26 * 26 * 26 + 475254
    int n = N - 475255;
    int q1 = n / (26 * 26 * 26 * 26);
    int r1 = n % (26 * 26 * 26 * 26);
    int q2 = r1 / (26 * 26 * 26);
    int r2 = r1 % (26 * 26 * 26);
    int q3 = r2 / (26 * 26);
    int r3 = r2 % (26 * 26);
    int q4 = r3 / (26);
    int r4 = r3 % (26);
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(r4));
  } else if (N <= 321272406) { // 26 * 26 * 26 * 26 * 26 * 26 + 12356630
    int n = N - 12356631;
    int q1 = n / (26 * 26 * 26 * 26 * 26);
    int r1 = n % (26 * 26 * 26 * 26 * 26);
    int q2 = r1 / (26 * 26 * 26 * 26);
    int r2 = r1 % (26 * 26 * 26 * 26);
    int q3 = r2 / (26 * 26 * 26);
    int r3 = r2 % (26 * 26 * 26);
    int q4 = r3 / (26 * 26);
    int r4 = r3 % (26 * 26);
    int q5 = r4 / 26;
    int r5 = r4 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(r5));
  } else if (N <= 8353082582) { // pow(26, 7) + ...
    int n = N - 321272407;
    int q1 = n / (26 * 26 * 26 * 26 * 26 * 26);
    int r1 = n % (26 * 26 * 26 * 26 * 26 * 26);
    int q2 = r1 / (26 * 26 * 26 * 26 * 26);
    int r2 = r1 % (26 * 26 * 26 * 26 * 26);
    int q3 = r2 / (26 * 26 * 26 * 26);
    int r3 = r2 % (26 * 26 * 26 * 26);
    int q4 = r3 / (26 * 26 * 26);
    int r4 = r3 % (26 * 26 * 26);
    int q5 = r4 / (26 * 26);
    int r5 = r4 % (26 * 26);
    int q6 = r5 / (26);
    int r6 = r5 % (26);
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(q6));
    ans.push_back(A.at(r6));
  } else if (N <= pow(26, 8) + 8353082582) { // pow(26, 8) + ...
    int n = N - 8353082583;
    int q1 = n / (long long)pow(26, 7);
    int r1 = n % (long long)pow(26, 7);
    int q2 = r1 / (long long)pow(26, 6);
    int r2 = r1 % (long long)pow(26, 6);
    int q3 = r2 / (long long)pow(26, 5);
    int r3 = r2 % (long long)pow(26, 5);
    int q4 = r3 / (long long)pow(26, 4);
    int r4 = r3 % (long long)pow(26, 4);
    int q5 = r4 / (long long)pow(26, 3);
    int r5 = r4 % (long long)pow(26, 3);
    int q6 = r5 / (long long)pow(26, 2);
    int r6 = r5 % (long long)pow(26, 2);
    int q7 = r6 / 26;
    int r7 = r6 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(q6));
    ans.push_back(A.at(q7));
    ans.push_back(A.at(r7));
  } else if (N <= pow(26, 9) + 217180147158) {
    int n = N - 217180147159;
    int q1 = n / (long long)pow(26, 8);
    int r1 = n % (long long)pow(26, 8);
    int q2 = r1 / (long long)pow(26, 7);
    int r2 = r1 % (long long)pow(26, 7);
    int q3 = r2 / (long long)pow(26, 6);
    int r3 = r2 % (long long)pow(26, 6);
    int q4 = r3 / (long long)pow(26, 5);
    int r4 = r3 % (long long)pow(26, 5);
    int q5 = r4 / (long long)pow(26, 4);
    int r5 = r4 % (long long)pow(26, 4);
    int q6 = r5 / (long long)pow(26, 3);
    int r6 = r5 % (long long)pow(26, 3);
    int q7 = r6 / (long long)pow(26, 2);
    int r7 = r6 % (long long)pow(26, 2);
    int q8 = r7 / 26;
    int r8 = r7 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(q6));
    ans.push_back(A.at(q7));
    ans.push_back(A.at(q8));
    ans.push_back(A.at(r8));
  } else if (N <= pow(26, 10) + 5646683826134) {
    int n = N - 5646683826135;
    int q1 = n / (long long)pow(26, 9);
    int r1 = n % (long long)pow(26, 9);
    int q2 = r1 / (long long)pow(26, 8);
    int r2 = r1 % (long long)pow(26, 8);
    int q3 = r2 / (long long)pow(26, 7);
    int r3 = r2 % (long long)pow(26, 7);
    int q4 = r3 / (long long)pow(26, 6);
    int r4 = r3 % (long long)pow(26, 6);
    int q5 = r4 / (long long)pow(26, 5);
    int r5 = r4 % (long long)pow(26, 5);
    int q6 = r5 / (long long)pow(26, 4);
    int r6 = r5 % (long long)pow(26, 4);
    int q7 = r6 / (long long)pow(26, 3);
    int r7 = r6 % (long long)pow(26, 3);
    int q8 = r7 / (long long)pow(26, 2);
    int r8 = r7 % (long long)pow(26, 2);
    int q9 = r8 / 26;
    int r9 = r8 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(q6));
    ans.push_back(A.at(q7));
    ans.push_back(A.at(q8));
    ans.push_back(A.at(q9));
    ans.push_back(A.at(r9));
  } else if (N <= pow(26, 11) + 146813779479510) {
    int n = N - 146813779479511;
    int q1 = n / (long long)pow(26, 10);
    int r1 = n % (long long)pow(26, 10);
    int q2 = r1 / (long long)pow(26, 9);
    int r2 = r1 % (long long)pow(26, 9);
    int q3 = r2 / (long long)pow(26, 8);
    int r3 = r2 % (long long)pow(26, 8);
    int q4 = r3 / (long long)pow(26, 7);
    int r4 = r3 % (long long)pow(26, 7);
    int q5 = r4 / (long long)pow(26, 6);
    int r5 = r4 % (long long)pow(26, 6);
    int q6 = r5 / (long long)pow(26, 5);
    int r6 = r5 % (long long)pow(26, 5);
    int q7 = r6 / (long long)pow(26, 4);
    int r7 = r6 % (long long)pow(26, 4);
    int q8 = r7 / (long long)pow(26, 3);
    int r8 = r7 % (long long)pow(26, 3);
    int q9 = r8 / (long long)pow(26, 2);
    int r9 = r8 % (long long)pow(26, 2);
    int q10 = r9 / 26;
    int r10 = r9 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(q6));
    ans.push_back(A.at(q7));
    ans.push_back(A.at(q8));
    ans.push_back(A.at(q9));
    ans.push_back(A.at(q10));
    ans.push_back(A.at(r10));
  } else if (N <= 1000000000000001) {
    int n = pow(26, 11) + 146813779479510 + pow(26, 12);
    int q1 = n / (long long)pow(26, 11);
    int r1 = n % (long long)pow(26, 11);
    int q2 = r1 / (long long)pow(26, 10);
    int r2 = r1 % (long long)pow(26, 10);
    int q3 = r2 / (long long)pow(26, 9);
    int r3 = r2 % (long long)pow(26, 9);
    int q4 = r3 / (long long)pow(26, 8);
    int r4 = r3 % (long long)pow(26, 8);
    int q5 = r4 / (long long)pow(26, 7);
    int r5 = r4 % (long long)pow(26, 7);
    int q6 = r5 / (long long)pow(26, 6);
    int r6 = r5 % (long long)pow(26, 6);
    int q7 = r6 / (long long)pow(26, 5);
    int r7 = r6 % (long long)pow(26, 5);
    int q8 = r7 / (long long)pow(26, 4);
    int r8 = r7 % (long long)pow(26, 4);
    int q9 = r8 / (long long)pow(26, 3);
    int r9 = r8 % (long long)pow(26, 3);
    int q10 = r9 / (long long)pow(26, 2);
    int r10 = r9 % (long long)pow(26, 2);
    int q11 = r10 / 26;
    int r11 = r10 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(q6));
    ans.push_back(A.at(q7));
    ans.push_back(A.at(q8));
    ans.push_back(A.at(q9));
    ans.push_back(A.at(q10));
    ans.push_back(A.at(q11));
    ans.push_back(A.at(r11));
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {

#define int long long

  long long N;
  cin >> N;
  vector<char> A = {'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'};

  string ans;
  if (N <= 26) {
    ans = A.at(N - 1);
  } else if (N <= 702) { // 26 * 26 + 26
    int n = N - 27;
    int f = n / 26;
    int s = n % 26;
    ans.push_back(A.at(f));
    ans.push_back(A.at(s));
  } else if (N <= 18278) { // 26 * 26 * 26 + 702
    int n = N - 703;       // n = 0 ~ 17575
    int q1 = n / (26 * 26);
    int r1 = n % (26 * 26);
    int q2 = r1 / (26);
    int r2 = r1 % (26);
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(r2));
  } else if (N <= 475254) { // 26 * 26 * 26 * 26 + 18278
    int n = N - 18279;
    int q1 = n / (26 * 26 * 26);
    int r1 = n % (26 * 26 * 26);
    int q2 = r1 / (26 * 26);
    int r2 = r1 % (26 * 26);
    int q3 = r2 / 26;
    int r3 = r2 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(r3));
  } else if (N <= 12356630) { // 26 * 26 * 26 * 26 * 26 + 475254
    int n = N - 475255;
    int q1 = n / (26 * 26 * 26 * 26);
    int r1 = n % (26 * 26 * 26 * 26);
    int q2 = r1 / (26 * 26 * 26);
    int r2 = r1 % (26 * 26 * 26);
    int q3 = r2 / (26 * 26);
    int r3 = r2 % (26 * 26);
    int q4 = r3 / (26);
    int r4 = r3 % (26);
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(r4));
  } else if (N <= 321272406) { // 26 * 26 * 26 * 26 * 26 * 26 + 12356630
    int n = N - 12356631;
    int q1 = n / (26 * 26 * 26 * 26 * 26);
    int r1 = n % (26 * 26 * 26 * 26 * 26);
    int q2 = r1 / (26 * 26 * 26 * 26);
    int r2 = r1 % (26 * 26 * 26 * 26);
    int q3 = r2 / (26 * 26 * 26);
    int r3 = r2 % (26 * 26 * 26);
    int q4 = r3 / (26 * 26);
    int r4 = r3 % (26 * 26);
    int q5 = r4 / 26;
    int r5 = r4 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(r5));
  } else if (N <= 8353082581) { // pow(26, 7) + ...
    int n = N - 321272406;
    int q1 = n / (26 * 26 * 26 * 26 * 26 * 26);
    int r1 = n % (26 * 26 * 26 * 26 * 26 * 26);
    int q2 = r1 / (26 * 26 * 26 * 26 * 26);
    int r2 = r1 % (26 * 26 * 26 * 26 * 26);
    int q3 = r2 / (26 * 26 * 26 * 26);
    int r3 = r2 % (26 * 26 * 26 * 26);
    int q4 = r3 / (26 * 26 * 26);
    int r4 = r3 % (26 * 26 * 26);
    int q5 = r4 / (26 * 26);
    int r5 = r4 % (26 * 26);
    int q6 = r5 / (26);
    int r6 = r6 % (26);
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(q6));
    ans.push_back(A.at(r6));
  } else if (N <= pow(26, 8) + 8353082581) { // pow(26, 8) + ...
    int n = N - 8353082582;
    int q1 = n / (long long)pow(26, 7);
    int r1 = n % (long long)pow(26, 7);
    int q2 = r1 / (long long)pow(26, 6);
    int r2 = r1 % (long long)pow(26, 6);
    int q3 = r2 / (long long)pow(26, 5);
    int r3 = r2 % (long long)pow(26, 5);
    int q4 = r3 / (long long)pow(26, 4);
    int r4 = r3 % (long long)pow(26, 4);
    int q5 = r4 / (long long)pow(26, 3);
    int r5 = r4 % (long long)pow(26, 3);
    int q6 = r5 / (long long)pow(26, 2);
    int r6 = r5 % (long long)pow(26, 2);
    int q7 = r6 / 26;
    int r7 = r6 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(q6));
    ans.push_back(A.at(q7));
    ans.push_back(A.at(r7));
  } else if (N <= pow(26, 9) + 217180147157) {
    int n = N - 217180147158;
    int q1 = n / (long long)pow(26, 8);
    int r1 = n % (long long)pow(26, 8);
    int q2 = r1 / (long long)pow(26, 7);
    int r2 = r1 % (long long)pow(26, 7);
    int q3 = r2 / (long long)pow(26, 6);
    int r3 = r2 % (long long)pow(26, 6);
    int q4 = r3 / (long long)pow(26, 5);
    int r4 = r3 % (long long)pow(26, 5);
    int q5 = r4 / (long long)pow(26, 4);
    int r5 = r4 % (long long)pow(26, 4);
    int q6 = r5 / (long long)pow(26, 3);
    int r6 = r5 % (long long)pow(26, 3);
    int q7 = r6 / (long long)pow(26, 2);
    int r7 = r6 % (long long)pow(26, 2);
    int q8 = r7 / 26;
    int r8 = r7 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(q6));
    ans.push_back(A.at(q7));
    ans.push_back(A.at(q8));
    ans.push_back(A.at(r8));
  } else if (N <= pow(26, 10) + 5646683826133) {
    int n = N - 5646683826134;
    int q1 = n / (long long)pow(26, 9);
    int r1 = n % (long long)pow(26, 9);
    int q2 = r1 / (long long)pow(26, 8);
    int r2 = r1 % (long long)pow(26, 8);
    int q3 = r2 / (long long)pow(26, 7);
    int r3 = r2 % (long long)pow(26, 7);
    int q4 = r3 / (long long)pow(26, 6);
    int r4 = r3 % (long long)pow(26, 6);
    int q5 = r4 / (long long)pow(26, 5);
    int r5 = r4 % (long long)pow(26, 5);
    int q6 = r5 / (long long)pow(26, 4);
    int r6 = r5 % (long long)pow(26, 4);
    int q7 = r6 / (long long)pow(26, 3);
    int r7 = r6 % (long long)pow(26, 3);
    int q8 = r7 / (long long)pow(26, 2);
    int r8 = r7 % (long long)pow(26, 2);
    int q9 = r8 / 26;
    int r9 = r8 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(q6));
    ans.push_back(A.at(q7));
    ans.push_back(A.at(q8));
    ans.push_back(A.at(q9));
    ans.push_back(A.at(r9));
  } else {
    int n = N - 146813779479510;
    int q1 = n / (long long)pow(26, 10);
    int r1 = n % (long long)pow(26, 10);
    int q2 = r1 / (long long)pow(26, 9);
    int r2 = r1 % (long long)pow(26, 9);
    int q3 = r2 / (long long)pow(26, 8);
    int r3 = r2 % (long long)pow(26, 8);
    int q4 = r3 / (long long)pow(26, 7);
    int r4 = r3 % (long long)pow(26, 7);
    int q5 = r4 / (long long)pow(26, 6);
    int r5 = r4 % (long long)pow(26, 6);
    int q6 = r5 / (long long)pow(26, 5);
    int r6 = r5 % (long long)pow(26, 5);
    int q7 = r6 / (long long)pow(26, 4);
    int r7 = r6 % (long long)pow(26, 4);
    int q8 = r7 / (long long)pow(26, 3);
    int r8 = r7 % (long long)pow(26, 3);
    int q9 = r7 / (long long)pow(26, 2);
    int r9 = r7 % (long long)pow(26, 2);
    int q10 = r9 / 26;
    int r10 = r9 % 26;
    ans.push_back(A.at(q1));
    ans.push_back(A.at(q2));
    ans.push_back(A.at(q3));
    ans.push_back(A.at(q4));
    ans.push_back(A.at(q5));
    ans.push_back(A.at(q6));
    ans.push_back(A.at(q7));
    ans.push_back(A.at(q8));
    ans.push_back(A.at(q9));
    ans.push_back(A.at(q10));
    ans.push_back(A.at(r10));
  }
  cout << ans << endl;
}