#include <bits/stdc++.h> #include <math.h> using namespace std; char slowo[1000001]; int main() { int n; long long k; scanf("%d %lld", &n, &k); long double p = 1; long double akt = 0; long double pot2 = 1; int length = 0; for(int i = 0; i < n - 1; i++) { pot2 *= 2; } long double cos = 1; for(int i = 0; i < n; i++) { akt += pot2 / cos; cos *= 2; } long double z = akt; if(k <= akt) { slowo[length] = 'a'; length++; } else if(k > akt && k <= akt*2) { slowo[length] = 'b'; p = akt + 1; length++; z = akt*2; } else if(k > akt*2 && k <= akt*3) { slowo[length] = 'c'; p = akt * 2 + 1; length++; z = akt*3; } else { printf("NIE"); return 0; } while(p < z) { if(k == p) { break; } p++; long double s = floor((p + z)/2); //cout<<p<<" "<<s<<" "<<z<<" "<<slowo[length - 1]<<endl; if(k > s) { if(slowo[length - 1] == 'a') { slowo[length] = 'c'; } if(slowo[length - 1] == 'b') { slowo[length] = 'c'; } if(slowo[length - 1] == 'c') { slowo[length] = 'b'; } p = s + 1; } else if(k <= s) { if(slowo[length - 1] == 'a') { slowo[length] = 'b'; } if(slowo[length - 1] == 'b') { slowo[length] = 'a'; } if(slowo[length - 1] == 'c') { slowo[length] = 'a'; } z = s; } length++; } for(int i = 0; i < length; i++) { printf("%c", slowo[i]); } printf("\n"); 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #include <bits/stdc++.h> #include <math.h> using namespace std; char slowo[1000001]; int main() { int n; long long k; scanf("%d %lld", &n, &k); long double p = 1; long double akt = 0; long double pot2 = 1; int length = 0; for(int i = 0; i < n - 1; i++) { pot2 *= 2; } long double cos = 1; for(int i = 0; i < n; i++) { akt += pot2 / cos; cos *= 2; } long double z = akt; if(k <= akt) { slowo[length] = 'a'; length++; } else if(k > akt && k <= akt*2) { slowo[length] = 'b'; p = akt + 1; length++; z = akt*2; } else if(k > akt*2 && k <= akt*3) { slowo[length] = 'c'; p = akt * 2 + 1; length++; z = akt*3; } else { printf("NIE"); return 0; } while(p < z) { if(k == p) { break; } p++; long double s = floor((p + z)/2); //cout<<p<<" "<<s<<" "<<z<<" "<<slowo[length - 1]<<endl; if(k > s) { if(slowo[length - 1] == 'a') { slowo[length] = 'c'; } if(slowo[length - 1] == 'b') { slowo[length] = 'c'; } if(slowo[length - 1] == 'c') { slowo[length] = 'b'; } p = s + 1; } else if(k <= s) { if(slowo[length - 1] == 'a') { slowo[length] = 'b'; } if(slowo[length - 1] == 'b') { slowo[length] = 'a'; } if(slowo[length - 1] == 'c') { slowo[length] = 'a'; } z = s; } length++; } for(int i = 0; i < length; i++) { printf("%c", slowo[i]); } printf("\n"); return 0; } |