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

#include <bits/stdc++.h>
#define MAX 1e15
#define ull unsigned long long
using namespace std;

int main() {
  ull n;
  cin >> n;
  char *str = (char *)malloc(1024 * sizeof(char));
  ull i = 0;
  while (n > 0) {
    ull rem = n % 26;
    if (rem == 0) {
      str[i++] = 'z';
      n = (n / 26) - 1;
    } else {
      str[i++] = (rem - 1) + 'a';
      n /= 26;
    }
  }
  str[i] = '\\0';
  reverse(str, str + strlen(str));
  cout << str << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define MAX 1e15
#define int unsigned long long int
using namespace std;

signed main() {
  int n;
  cin >> n;
  char *str = (char *)malloc(n * sizeof(char));
  int i = 0, rem = 0;
  while (n > 0) {
    rem = n % 26;
    if (rem == 0) {
      str[i++] = 'z';
      n = (n / 26) - 1;
    } else {
      str[i++] = (rem - 1) + 'a';
      n /= 26;
    }
  }
  str[i] = '\\0';
  reverse(str, str + strlen(str));
  cout << str << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long N;
  cin >> N;
  string res = "";
  while (N) {
    --N;
    res += (char)('a' + (N % 26));
    N /= 26;
  }
  reverse(res.begin(), res.end());
  cout << res << endl;
}

Error: 0

Fixed submission:

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

vector<string> st;
ll k;

void dfs(string s, char mx) {
  if (s.size() == k) {
    st.push_back(s);
    return;
  }
  for (char c = 'a'; c <= mx + 1; c++) {
    string t = s;
    t += c;
    dfs(t, max(mx, c));
  }
}

int main() {
  ll n;
  cin >> n;
  if (n <= 26) {
    char s1 = 'a' + (n - 1);
    cout << s1 << endl;
    return 0;
  }
  ll keta = 0;
  ll n1 = n;
  while (n1 > 0) {
    n1 /= 26;
    keta++;
  }
  n -= pow(26, keta - 1);
  k = keta;
  dfs("", 'a' - 1);
  cout << st[n - 1] << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF 2147483640
using namespace std;
unsigned long long a[20];
int main() {
  // freopen("out.txt","w",stdout);
  for (unsigned long long i = 1, j = 26; i <= 11; i++, j *= 26)
    a[i] = j;
  unsigned long long n, len, sum = 0;
  cin >> n;
  n--;
  for (len = 1;; len++) {
    if (sum + a[len] > n)
      break;
    sum += a[len];
  }
  n -= sum;
  string ans;
  for (int i = len - 1; i > 0; i--) {
    ans.push_back('a' + n / a[i]);
    n = n % a[i];
  }
  ans.push_back('a' + n);
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define INF 2147483640
using namespace std;
unsigned long long a[20];
int main() {
  // freopen("out.txt","w",stdout);
  for (unsigned long long i = 1, j = 26; i <= 10; i++, j *= 26)
    a[i] = j;
  unsigned long long n, len, sum = 0;
  cin >> n;
  for (len = 1;; len++) {
    if (sum + a[len] > n)
      break;
    sum += a[len];
  }
  n -= sum;
  string ans;
  for (int i = len - 1; i; i--) {
    ans.push_back('a' + n / a[i]);
    n %= a[i];
  }
  ans.push_back('a' + n - 1);
  cout << ans;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int

#define vl vector<ll>
#define vi vector<int>

#define ff first
#define ss second

#define pb push_back
#define MOD 1000000007
// const int nax = 1e6+5;
#define inf 4e18

#define display(v)                                                             \\
  for (int i = 0; i < v.size(); ++i)                                           \\
  cout << v[i] << " "
#define all(v) v.begin(), v.end()
ll sqr(ll x) { return x * x; }
inline ll add(ll a, ll b) {
  ll c = a + b;
  if (c >= MOD)
    c -= MOD;
  return c;
}
inline ll mul(ll a, ll b) { return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b) {
  ll c = a - b;
  if (c < 0)
    c += MOD;
  return c;
}
const int nax = 100 * 1000 + 10;

ll mx = 1000000000000001;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n;
  cin >> n; // n--;
  string str;
  int i = 1;
  ll ok = 26;
  while (n) {
    ll v = n % 26;
    if (v == 0) {
      v = 26;
      n = (n - 1) / 26;
    } else {
      n /= 26;
    }
    str += (char)(v - 1 + 'a');
  }
  reverse(all(str));
  cout << str;

  return 0;
}

// Химаншу

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int

#define vl vector<ll>
#define vi vector<int>

#define ff first
#define ss second

#define pb push_back
#define MOD 1000000007
// const int nax = 1e6+5;
#define inf 4e18

#define display(v)                                                             \\
  for (int i = 0; i < v.size(); ++i)                                           \\
  cout << v[i] << " "
#define all(v) v.begin(), v.end()
ll sqr(ll x) { return x * x; }
inline ll add(ll a, ll b) {
  ll c = a + b;
  if (c >= MOD)
    c -= MOD;
  return c;
}
inline ll mul(ll a, ll b) { return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b) {
  ll c = a - b;
  if (c < 0)
    c += MOD;
  return c;
}
const int nax = 100 * 1000 + 10;

ll mx = 1000000000000001;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n;
  cin >> n;
  string str;
  while (n) {
    ll v = n % 26;
    if (n == 26)
      n /= 26;
    if (v == 0)
      v = 26, n--;
    str += (char)(v - 1 + 'a');
  }
  reverse(all(str));
  cout << str;

  return 0;
}

// Химаншу
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

int main() {
  long long N;
  cin >> N;
  string res = "";
  while (N) {
    --N;
    res += (char)('a' + (N % 26));
    N /= 26;
  }
  reverse(res.begin(), res.end());
  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>

int main() {
  long long int i = -1, n = 1;
  char buf[1024];
  char ss[1024];
  char english[26] = {'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 (i < 0) {
    scanf("%d", &i);
  }
  n = 26;
  sprintf(ss, "", n);
  while (i > 0) {
    long long int amari;
    amari = i % n;
    char amari2 = english[amari - 1];
    sprintf(buf, "%c%s", amari2, ss);
    strcpy(ss, buf);
    i = i / n;
  }
  puts(ss);
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;

int main() {
  long int N;
  // int N;
  int alpha;
  alpha = 26;
  cin >> N;

  char moji;
  vector<char> moji_list;
  vector<int> Y;
  int i;

  for (moji = 'a'; moji <= 'z'; ++moji) {
    moji_list.push_back(moji);
  }

  /*
  for(i=0;i<=26;i++){
      cout << moji_list[i] << endl;
  }
  */

  long int syo;
  // int syo;
  if (N <= alpha) {
    cout << moji_list[N - 1] << endl;
    return 0;
  }
  while (N > alpha) {
    syo = (long int)((N - 1) / alpha);
    // syo = (N / alpha);
    if (N % alpha == 0) {
      Y.push_back((int)(alpha));
    } else {
      Y.push_back((int)(N % alpha));
    }
    N = syo;
    // cout << N << endl;
  }

  Y.push_back((int)(N));

  for (i = Y.size() - 1; i >= 0; i--) {
    // cout << Y[i] << endl;
    cout << moji_list[Y[i] - 1];
    // cout << i << endl;
  }
  cout << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  long int N;
  int alpha;
  alpha = 26;
  cin >> N;

  char moji;
  vector<char> moji_list;
  vector<int> Y;
  int i;

  for (moji = 'a'; moji <= 'z'; ++moji) {
    moji_list.push_back(moji);
  }

  int syo;
  if (N <= alpha) {
    cout << moji_list[N - 1] << endl;
    return 0;
  }
  while (N > alpha) {
    syo = N / alpha;
    Y.push_back(N % alpha);
    N = syo;
    // cout << N << endl;
  }

  Y.push_back(N);

  for (i = Y.size() - 1; i >= 0; i--) {
    cout << moji_list[Y[i] - 1];
  }
  cout << endl;

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

// g++ -std=gnu++14 a.cpp
// #include <bits/stdc++.h>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

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

  int keta;
  ll m = 26;

  for (int i = 1; i < 15; i++) {
    if (m >= N) {
      keta = i;
      break;
    } else {
      ll plus = 1;
      rep(j, i + 1) plus *= 26;
      m = m + plus;
    }
  }

  ll ban = N;
  ll minus = 26;
  for (int i = 1; i < keta; i++) {
    ban -= minus;
    minus *= 26;
  }
  ban--;

  // cout << ban << endl;

  rep(i, keta) {
    ll w = 26;
    char s = ban % w;
    ans += ('a' + s);
    ban /= 26;
  }

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

  cout << ans << endl;
  /*
    ll wari = 1;
    rep(i,keta-1)wari *= 26;

    while(N > 0){
      int t;
      for(int i = 1;i <= 26;i++){
        if(wari*26 <= N){
          t = 26;
          break;
        }
        if(wari*i > N){
          t = i-1;
          break;
        }else{
          continue;
        }
      }

      char s = 96 + t;
      ans += s;
      N -= wari*t;
      if(wari != 1)wari /= 26;
    }

    cout << ans << endl;
  */
}


Error: 0

Fixed submission:

// g++ -std=gnu++14 a.cpp
// #include <bits/stdc++.h>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

vector<int> sort(vector<int> &v) {
  int l = v.size();
  int i = 0;
  while (i != l - 1) {
    for (int j = l - 1; j > i; j--)
      if (v[j - 1] > v[j])
        swap(v[j], v[j - 1]);
    i++;
  }
  return v;
}

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

  ll par = 1;
  int keta;
  ll m = 26;

  for (int i = 1; i < 20; i++) {
    if (m >= N) {
      keta = i;
      break;
    } else {
      m = m + m * 26;
    }
  }
  int wari = 1;
  rep(i, keta - 1) wari *= 26;
  // vector<int> ans;
  while (N > 0) {
    int t = N / (wari);
    if (t == 27)
      t--;
    char s = 96 + t;
    ans += s;
    N -= wari * t;
    if (wari != 1)
      wari /= 26;
  }

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

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

int main() {
  long long int N, n;
  cin >> N;
  // cout << N;
  n = N;

  string s;
  s = "zabcdefghijklmnopqrstuvwxyz";

  vector<int> A(100, -1);
  long long int i = 0;
  if (N == 1) {
    cout << 'a' << endl;
    return 0;
  }
  while (n > 0) {
    A.at(i) = n % 26;
    if (A.at(i) == 0) {
      n -= 26;
    }
    n -= A.at(i);
    n = n / 26;
    // cout << A.at(i);

    i++;
  }
  // cout << i << endl;

  for (long long int j = i - 1; j > -1; j--) {

    cout << s.at(A.at(j));
  }
  cout << endl;
}


Error: 0

Fixed submission:

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

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

  int a, b, c, d, e, f, n;
  n = N;

  string s;
  s = "abcdefghijklmnopqrstuvwxyz";

  vector<int> A(100);
  int i = 0;
  while (n > 0) {
    // cout << n << " " << n%26;
    A.at(i) = n % 26;
    n = n / 26;

    // cout << A.at(i)  << " ";
    i++;
  }
  // cout << " d" <<i << endl;

  for (int j = 0; j < 100; j++) {
    // cout << A.at(j) << " ";
  }
  // cout << endl;

  for (int j = i - 1; j > -1; j--) {
    // cout <<"ans: ";
    cout << s.at(A.at(j) - 1);
  }
  cout << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
char findans(int k) {
  char aaa[26] = {'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'};
  return aaa[k - 1];
}
int main() {
  long long int n;
  cin >> n;
  string s;
  if (n <= 26)
    cout << findans(n) << endl;
  else {
    while (n > 0) {
      n--;
      char ans = 'a' + (char)(n % 26);
      s += ans;
      //  cout<<ans;
      n = n / 26;
    }
    // if(n>0)
    // s+=findans(n);

    for (int i = s.length() - 1; i >= 0; i--)
      cout << s[i];
    cout << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
char findans(int k) {
  char a[26] = {'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'};
  return a[k - 1];
}
int main() {
  long long int n;
  cin >> n;
  vector<char> s;
  if (n <= 26)
    cout << findans(n) << endl;
  else {
    while (n > 26) {
      char ans = findans(n % 26);
      s.push_back(ans);
      n = n / 26;
    }
    s.push_back(n);
    for (int i = s.size() - 1; i >= 0; i++)
      cout << s[i];
    cout << endl;
  }
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

ll n;
string s;
string alter(char p) {
  string str = "";
  str += p;
  return str;
}

ll qqpow(ll a, ll n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 1)
    return qqpow(a, n - 1) * a;
  else {
    ll tempp = qqpow(a, n / 2);
    return tempp * tempp;
  }
}
string dfs(ll m, ll k) {
  //	cout <<  m << ' ' <<  k << endl;
  ll x = qqpow(26, k);
  if (m > x)
    return dfs(m - x, k + 1);
  if (k == 1) {
    char p = 'a' + m - 1;
    string q = alter(p);
    return q;
  }
  x /= 26;
  ll ex = (m - 1) / x;
  char p = 'a' + ex;
  return p + dfs(m - ex * x, k - 1);
}
int main() {
  cin >> n;
  s = dfs(n, 1);
  cout << s;
  return 0;
}

Error: WA

Fixed submission:

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

ll n;
string s;
string alter(char p) {
  string str = "";
  str += p;
  return str;
}

ll qqpow(ll a, ll n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 1)
    return qqpow(a, n - 1) * a;
  else {
    int tempp = qqpow(a, n / 2);
    return tempp * tempp;
  }
}
string dfs(ll m, ll k) {
  ll x = qqpow(26, k);
  if (m > x)
    return dfs(m - x, k + 1);
  if (k == 1) {
    char p = 'a' + m - 1;
    string q = alter(p);
    return q;
  }
  x /= 26;
  ll ex = m / x;
  char p = 'a' + ex;
  return p + dfs(m - ex * x, k - 1);
}
int main() {
  cin >> n;
  s = dfs(n, 1);
  cout << s;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  vector<int> a(11, -1);
  ll n;
  cin >> n;
  for (int i = 0; i < 11; i++) {
    int x;
    if (n % 26 != 0) {
      x = n % 26;
    } else {
      x = 26;
    }
    a[10 - i] = x;
    n -= x;
    if (n == 0)
      break;
    n /= 26;
  }

  for (int i = 0; i < 11; i++) {
    if (a[i] != -1) {
      cout << (char)(96 + a[i]);
    }
  }
  cout << endl;

  return 0;
}

Error: 0

Fixed submission:

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

ll q(int n) {
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= 26;
  }
  return ans;
}

int main() {
  ll n;
  cin >> n;
  ll a = 0;
  int le;
  for (int i = 1; i < 12; i++) {
    if (a < n && n <= q(i)) {
      le = i;
      break;
    }
    a += q(i);
  }

  vector<int> b(le);
  for (int i = 0; i < le; i++) {
    ll x = n / 26;
    ll y = n - x * 26;
    b[i] = y;
    n = x;
  }
  reverse(b.begin(), b.end());
  for (int i = 0; i < le; i++) {
    cout << (char)(96 + b[i]);
  }
  cout << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
string each_digit(long long num, long long count) {
  long long n = num;
  int p = 0;
  string ans = "";
  vector<char> str(count, 'a');
  vector<long long> surp(count);
  while (1) {
    if (!n)
      break;
    surp[p] = n % 26;
    n /= 26;
    p++;
  }
  for (int i = count - 1; i >= 0; i--) {
    ans += (char)(str[i] + surp[i]);
  }

  return ans;
};

int main() {
  long long n;
  long long alp_count = 26, base_count = 1;
  string val;
  cin >> n;
  while (1) {
    if (n > alp_count) {
      n -= alp_count;
      alp_count *= 26;
      base_count++;
    } else {
      // cout << base_count << endl;
      cout << each_digit(n - 1, base_count) << endl;
      break;
    }
  }
  // cout << (char)('a'+5) << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
string each_digit(long long num, long long count) {
  long long n = num;
  int i = 0;
  string ans = "";
  vector<char> str(count, 'a');
  vector<long long> surp(count);
  while (1) {
    surp[i] = n % 26;
    if (!n)
      break;
    n /= 26;
    i++;
  }
  for (int i = count - 1; i >= 0; i--) {
    ans += (char)(str[i] + surp[i]);
  }

  return ans;
};

int main() {
  long long n;
  long long alp_count = 26, base_count = 1;
  string val;
  cin >> n;
  while (1) {
    if (n > alp_count) {
      n -= alp_count;
      alp_count *= 26;
      base_count++;
    } else {
      // cout << base_count << endl;
      cout << each_digit(n - 1, base_count) << endl;
      break;
    }
  }
  // cout << (char)('a'+5) << endl;
}
Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
// cout << fixed << setprecision(8) << a << endl;
#define Fast_Input                                                             \\
  ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type, greater<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
/*sort(v.begin(), v.end(),
     [](const pair<int, int>& x, const pair<int, int>& y)
{
    if (x.first != y.first)
        return x.first < y.first;
    return x.second < y.second;
});
*/
int const fx[] = {+1, +0, -1, +1};
int const fy[] = {-1, +1, +0, +0};
const int inf = numeric_limits<int>::max();
const int mx = 2e5;
const ll mod = 1e9 + 7;
ll pow(ll x, ll n) {
  ll res = 1;
  while (n) {
    if (n % 2) {
      res = res * x;
      n--;
    }
    x = x * x;
    n /= 2;
  }
  return res;
}
int main() {
  string s = "aabcdefghijklmnopqrstuvwxyz";
  ll n, i, sum = 0;
  cin >> n;
  i = 0;
  while (sum < n) {
    i++;
    sum += pow(ll(26), i);
  }
  i--;
  vector<char> v(20);
  int j;
  for (j = i; j >= 0; j--) {
    int y = n % 26;
    if (y == 0)
      y = 26;
    v[j] = s[y];
    n -= y;
    n /= 26;
  }
  for (j = 0; j <= i; j++)
    cout << v[j];
  cout << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
// cout << fixed << setprecision(8) << a << endl;
#define Fast_Input                                                             \\
  ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type, greater<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
/*sort(v.begin(), v.end(),
     [](const pair<int, int>& x, const pair<int, int>& y)
{
    if (x.first != y.first)
        return x.first < y.first;
    return x.second < y.second;
});
*/
int const fx[] = {+1, +0, -1, +1};
int const fy[] = {-1, +1, +0, +0};
const int inf = numeric_limits<int>::max();
const int mx = 2e5;
const ll mod = 1e9 + 7;
ll pow(ll x, ll n) {
  ll res = 1;
  while (n) {
    if (n % 2) {
      res = res * x;
      n--;
    }
    x = x * x;
    n /= 2;
  }
  return res;
}
int main() {
  string s = "aabcdefghijklmnopqrstuvwxyz";
  ll n, i, sum = 0;
  cin >> n;
  i = 0;
  while (sum < n) {
    i++;
    sum += pow(ll(26), i);
  }
  i--;
  vector<char> v(i);
  int j;
  for (j = i; j >= 0; j--) {
    int y = n % 26;
    if (y == 0)
      y = 26;
    v[j] = s[y];
    n -= y;
    n /= 26;
  }
  for (j = 0; j <= i; j++)
    cout << v[j];
  cout << endl;
  return 0;
}
Problem p02629 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

// codeforces 651

#define ll long long

ll mypow(int base, int p) {
  ll res = 1;
  for (int i = 0; i < p; i++)
    res *= base;
  return res;
}

int main() {

  ll num;
  cin >> num;
  int len = 1;
  ll lim = 26;
  ll prevLim = 0;
  while (lim < num) {
    len++;
    prevLim = lim;
    lim = mypow(26, len) + lim;
    // cout << " lim = " << lim << " len = " << len << endl;
  }

  if (num < 27) {
    cout << (char)(num + ((int)'a' - 1)) << endl;
    return 0;
  }

  // cout << " num = " << num << " prevLim = " << prevLim << endl;

  lim = num - prevLim - 1;
  vector<int> digs(len, 0);
  int currPow = len - 1;
  while (lim) {
    // cout << " lim = " << lim << endl;
    ll reduce = mypow(26, currPow);
    // cout << "    can we reduce " << reduce << "?";
    if (lim >= reduce) {
      // cout << " yes! " << endl;
      // lim -= reduce;
      // digs[currPow]++;
      digs[currPow] += (lim / reduce);
      lim -= (reduce * (lim / reduce));
    } else {
      // cout << " no... reducing pow to " << (currPow - 1) << endl;
      currPow--;
    }
  }
  string s("");
  for (int i = digs.size() - 1; i >= 0; i--)
    s = s + (char)(digs[i] + ((int)'a'));

  cout << s << endl;
  // cout << "lim = " << lim << " len = " << len << endl;

  return 0;
}


Error: TLE

Fixed submission:


#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

// codeforces 651

#define ll long long

ll mypow(int base, int p) {
  int res = 1;
  for (int i = 0; i < p; i++)
    res *= base;
  return res;
}

int main() {

  ll num;
  cin >> num;
  int len = 1;
  ll lim = 26;
  ll prevLim = 0;
  while (lim < num) {
    len++;
    prevLim = lim;
    lim = mypow(26, len) + lim;
  }

  if (num < 27) {
    cout << (char)(num + ((int)'a' - 1)) << endl;
    return 0;
  }

  // cout << " num = " << num << " prevLim = " << prevLim << endl;

  lim = num - prevLim - 1;
  vector<int> digs(len, 0);
  int currPow = len - 1;
  while (lim) {
    // cout << " lim = " << lim << endl;
    ll reduce = mypow(26, currPow);
    // cout << "    can we reduce " << reduce << "?";
    if (lim >= reduce) {
      // cout << " yes! " << endl;
      // lim -= reduce;
      // digs[currPow]++;
      digs[currPow] += (lim / reduce);
      lim -= (reduce * (lim / reduce));
    } else {
      // cout << " no... reducing pow to " << (currPow - 1) << endl;
      currPow--;
    }
  }
  string s("");
  for (int i = digs.size() - 1; i >= 0; i--)
    s = s + (char)(digs[i] + ((int)'a'));

  cout << s << endl;
  // cout << "lim = " << lim << " len = " << len << endl;

  return 0;
}