1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <vector>
using namespace std;
vector<int> slowo;
int main() {
	ios_base::sync_with_stdio(0);
	int count=0;
	unsigned long long index=0;
	cin >> count;
	cin >> index;
	index--;
	unsigned long long perlet=(2ULL<<min(63,count-1))-1ULL;
	if(perlet<=1ULL<<63&&index>perlet*3ULL-1ULL){
		cout<<"NIE";
		return 0;
	}
	if(count>64){
		slowo.push_back(0);
	}
	else{
		int first=index/perlet;
		slowo.push_back(first);
		index %= perlet;
	}
	for(int i=1;i<count;i++){
		bool overflow=count-i>63;
		unsigned long long range=(2ULL<<min(63,count-i))-1ULL;
		if(index==0){
			break;
		}
		else if(overflow || index<(range>>1)+1ULL){
			if(slowo.back()>0)
				slowo.push_back(0);
			else
				slowo.push_back(1);
			index-=1ULL;
		}
		else{
			if(slowo.back()>1)
				slowo.push_back(1);
			else
				slowo.push_back(2);
			index-=(range>>1)+1ULL;
		}
	}
	for(unsigned int i=0;i<slowo.size();i++){
		if(slowo[i]==0)
			cout<<'a';
		else if(slowo[i]==1)
			cout<<'b';
		else
			cout<<'c';
	}
	cout<<endl;
	return 0;
}