#include<cstdio> #include<algorithm> using namespace std; typedef long long LL; LL n; LL k; LL akt; LL newN = 1; char small,big; void inline switchLetters(char x) { if(x=='a') { small = 'b'; big = 'c'; } else if (x=='b') { small = 'a'; big = 'c'; } else { small = 'a'; big = 'b'; } } void go2() { while(k>1 && akt > 0) { //printf("\n%c%c-> k: %lld, akt: %lld\n",small,big,k,akt); k-=1; if(k<=akt-1) { //printf("%c",small); putchar(small); switchLetters(small); } else { k-=akt-1; //printf("%c", big); putchar(big); switchLetters(big); } akt/=2; } } void go() { //printf("N:%lld newN:%lld\n",n,newN); //ile literek można wypisać na pałę? LL x = 0; LL calc = 2; while(calc-1<k-(n-x)){ calc*=2; x++; } //printf("Na pale: %lld, x: %lld, n: %lld\n",n-x,x,n); int op = 1; bool byl = false; if(x<n) { while(n>x && k>1) { byl = true; if(op) { //printf("a"); putchar('a'); op=0; } else { //printf("b"); putchar('b'); op=1; } n--; k--; } //printf("\nKONIEC n: %lld\n\n",n); } akt = 1; while(n--) { akt*=2; } if(byl) { k++; if(op) { small = 'a'; big = 'c'; } else { small = 'b'; big = 'c'; } go2(); printf("\n"); //printf("\nKONIEC\n"); return; } //printf("AKT %lld\n", akt); //printf("K: %lld TEST:%lld\n", k, 3*(akt-1)); if (k<=akt-1) { //printf("a"); putchar('a'); small = 'b'; big = 'c'; akt/=2; go2(); } else { k-=akt-1; if(k<=akt-1) { //printf("b"); putchar('b'); small = 'a'; big = 'c'; akt/=2; go2(); } else { k-=akt-1; //printf("c"); putchar('c'); small = 'a'; big = 'b'; akt/=2; go2(); } } printf("\n"); } int main(){ scanf("%lld %lld",&n,&k); //recalc n newN = 0; LL calc = 1; while (3*(calc-1)<k) { calc*=2; newN++; //printf("%lld\n", calc); } //printf("newN: %lld, n: %lld, calc: %lld, k: %lld\n",newN,n,calc,k); if(n<newN) { printf("NIE\n"); } else { go(); } 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | #include<cstdio> #include<algorithm> using namespace std; typedef long long LL; LL n; LL k; LL akt; LL newN = 1; char small,big; void inline switchLetters(char x) { if(x=='a') { small = 'b'; big = 'c'; } else if (x=='b') { small = 'a'; big = 'c'; } else { small = 'a'; big = 'b'; } } void go2() { while(k>1 && akt > 0) { //printf("\n%c%c-> k: %lld, akt: %lld\n",small,big,k,akt); k-=1; if(k<=akt-1) { //printf("%c",small); putchar(small); switchLetters(small); } else { k-=akt-1; //printf("%c", big); putchar(big); switchLetters(big); } akt/=2; } } void go() { //printf("N:%lld newN:%lld\n",n,newN); //ile literek można wypisać na pałę? LL x = 0; LL calc = 2; while(calc-1<k-(n-x)){ calc*=2; x++; } //printf("Na pale: %lld, x: %lld, n: %lld\n",n-x,x,n); int op = 1; bool byl = false; if(x<n) { while(n>x && k>1) { byl = true; if(op) { //printf("a"); putchar('a'); op=0; } else { //printf("b"); putchar('b'); op=1; } n--; k--; } //printf("\nKONIEC n: %lld\n\n",n); } akt = 1; while(n--) { akt*=2; } if(byl) { k++; if(op) { small = 'a'; big = 'c'; } else { small = 'b'; big = 'c'; } go2(); printf("\n"); //printf("\nKONIEC\n"); return; } //printf("AKT %lld\n", akt); //printf("K: %lld TEST:%lld\n", k, 3*(akt-1)); if (k<=akt-1) { //printf("a"); putchar('a'); small = 'b'; big = 'c'; akt/=2; go2(); } else { k-=akt-1; if(k<=akt-1) { //printf("b"); putchar('b'); small = 'a'; big = 'c'; akt/=2; go2(); } else { k-=akt-1; //printf("c"); putchar('c'); small = 'a'; big = 'b'; akt/=2; go2(); } } printf("\n"); } int main(){ scanf("%lld %lld",&n,&k); //recalc n newN = 0; LL calc = 1; while (3*(calc-1)<k) { calc*=2; newN++; //printf("%lld\n", calc); } //printf("newN: %lld, n: %lld, calc: %lld, k: %lld\n",newN,n,calc,k); if(n<newN) { printf("NIE\n"); } else { go(); } return 0; } |