#include<iostream> #include<vector> #include<algorithm> #include<cmath> using namespace std; unsigned int n, i, d, l; unsigned long long k, p, pot64[64]= {1}; char z; char next(char z){ if(z == 'a') return 'b'; if(z == 'b') return 'a'; return 'a'; } char nextnext(char z){ if(z == 'a') return 'c'; if(z == 'b') return 'c'; return 'b'; } int main() { ios_base::sync_with_stdio(0); cin >> n >> k; for(i = 1; i < 64; ++i) pot64[i] = pot64[i-1]*2; //for(i = 1; i < 64; ++i) cout << pot64[i] <<" ";cout << endl; l = 1; if (n < 62 && k > 3*(pot64[n] -1) ) cout <<"NIE"; else { if (n >= 62) z = 'a'; else if(k <= (pot64[n]-1) ) z = 'a'; else if (k <= 2*(pot64[n]-1) ) {z = 'b'; k = k - (pot64[n]-1) ;} else { z = 'c'; k = k - 2*(pot64[n]-1) ;} if (n < 64) p = (pot64[n]-1); else p = pot64[63]; while(n){ cout << z; if(k == 1) break; p--; //cout <<"\n l = " << l << endl; //cout <<"\n p = " << p << endl; k--; n--; if (n > 63 || k <= p/2) z = next(z); else { z = nextnext(z); k = k - pot64[n] + 1; } //cout <<"\n n = " << n << endl; //cout <<"\n k = " << k << endl; if(n < 64) p = pot64[n] - 1; } } return 0; }
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> #include<algorithm> #include<cmath> using namespace std; unsigned int n, i, d, l; unsigned long long k, p, pot64[64]= {1}; char z; char next(char z){ if(z == 'a') return 'b'; if(z == 'b') return 'a'; return 'a'; } char nextnext(char z){ if(z == 'a') return 'c'; if(z == 'b') return 'c'; return 'b'; } int main() { ios_base::sync_with_stdio(0); cin >> n >> k; for(i = 1; i < 64; ++i) pot64[i] = pot64[i-1]*2; //for(i = 1; i < 64; ++i) cout << pot64[i] <<" ";cout << endl; l = 1; if (n < 62 && k > 3*(pot64[n] -1) ) cout <<"NIE"; else { if (n >= 62) z = 'a'; else if(k <= (pot64[n]-1) ) z = 'a'; else if (k <= 2*(pot64[n]-1) ) {z = 'b'; k = k - (pot64[n]-1) ;} else { z = 'c'; k = k - 2*(pot64[n]-1) ;} if (n < 64) p = (pot64[n]-1); else p = pot64[63]; while(n){ cout << z; if(k == 1) break; p--; //cout <<"\n l = " << l << endl; //cout <<"\n p = " << p << endl; k--; n--; if (n > 63 || k <= p/2) z = next(z); else { z = nextnext(z); k = k - pot64[n] + 1; } //cout <<"\n n = " << n << endl; //cout <<"\n k = " << k << endl; if(n < 64) p = pot64[n] - 1; } } return 0; } |