b

 avatar
user_8384735
c_cpp
2 years ago
1.0 kB
5
Indexable
// B.cpp solve1
#include<iostream>
using namespace std;
typedef long long LL;
LL path[5] = {1,2,3,4,5};
int main(){
    LL n;
    cin >> n;
    string s = "abcde";
    LL x = 2;
    for (int i = 1; path[4] < n; i++){
        for (int j = 0; j < 5; j++){
            if (j){
                path[j] = path[j - 1] + x;
            }else {
                path[0] = path[4] + x;
            }
        }
        x <<= 1;
    }
    for (int i = 0; i < 5; i++){
        if (path[i] >= n){
            cout << s[i];
            return 0;
        }
    }
}
// solve2
#include <iostream>

using namespace std;

int main () {
    int n, sum = 5, t = 1;
    cin >> n;
    while(1) { 
        if (n - sum <= 0) {
            if (n == 0) {
                cout << "e";
                break;
            }
            if (n % t == 0) n = n / t - 1;
            else n = n / t;
            cout << (char)(n + 'a');
            break;
        }
        else {
            t *= 2 ;
            n -= sum;
            sum *= 2;
        }
    }
    return 0;
}
Editor is loading...