import java.io.IOException; import java.io.InputStream; public class slo { public static void main(String[] args) throws IOException { InputStream is = System.in; int n = (int) getInt(is); long k = getInt(is); long words = powersCache[Math.min(n - 1, 59)]; char lastChar; if (k <= words) { lastChar = 'a'; } else if (k <= words * 2) { k -= words; lastChar = 'b'; } else if (k <= words * 3) { k -= words * 2; lastChar = 'c'; } else { System.out.println("NIE"); return; } System.out.print(lastChar); k -= 1; n -= 1; while (k > 0) { words = powersCache[Math.min(n - 1, 59)]; if (k <= words) { if (lastChar == 'a') { lastChar = 'b'; } else { lastChar = 'a'; } } else { if (lastChar == 'c') { lastChar = 'b'; } else { lastChar = 'c'; } k -= words; } System.out.print(lastChar); n -= 1; k -= 1; } } private static final long[] powersCache = { 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295L, 8589934591L, 17179869183L, 34359738367L, 68719476735L, 137438953471L, 274877906943L, 549755813887L, 1099511627775L, 2199023255551L, 4398046511103L, 8796093022207L, 17592186044415L, 35184372088831L, 70368744177663L, 140737488355327L, 281474976710655L, 562949953421311L, 1125899906842623L, 2251799813685247L, 4503599627370495L, 9007199254740991L, 18014398509481984L, 36028797018963968L, 72057594037927936L, 144115188075855872L, 288230376151711744L, 576460752303423488L, 1152921504606846976L }; private static long getInt(InputStream is) throws IOException { long value = 0; int chr = is.read(); while (chr >= '0' && chr <= '9') { value *= 10; value += chr - '0'; chr = is.read(); } if (chr == '\r') { is.read(); } return value; } }
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 | import java.io.IOException; import java.io.InputStream; public class slo { public static void main(String[] args) throws IOException { InputStream is = System.in; int n = (int) getInt(is); long k = getInt(is); long words = powersCache[Math.min(n - 1, 59)]; char lastChar; if (k <= words) { lastChar = 'a'; } else if (k <= words * 2) { k -= words; lastChar = 'b'; } else if (k <= words * 3) { k -= words * 2; lastChar = 'c'; } else { System.out.println("NIE"); return; } System.out.print(lastChar); k -= 1; n -= 1; while (k > 0) { words = powersCache[Math.min(n - 1, 59)]; if (k <= words) { if (lastChar == 'a') { lastChar = 'b'; } else { lastChar = 'a'; } } else { if (lastChar == 'c') { lastChar = 'b'; } else { lastChar = 'c'; } k -= words; } System.out.print(lastChar); n -= 1; k -= 1; } } private static final long[] powersCache = { 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295L, 8589934591L, 17179869183L, 34359738367L, 68719476735L, 137438953471L, 274877906943L, 549755813887L, 1099511627775L, 2199023255551L, 4398046511103L, 8796093022207L, 17592186044415L, 35184372088831L, 70368744177663L, 140737488355327L, 281474976710655L, 562949953421311L, 1125899906842623L, 2251799813685247L, 4503599627370495L, 9007199254740991L, 18014398509481984L, 36028797018963968L, 72057594037927936L, 144115188075855872L, 288230376151711744L, 576460752303423488L, 1152921504606846976L }; private static long getInt(InputStream is) throws IOException { long value = 0; int chr = is.read(); while (chr >= '0' && chr <= '9') { value *= 10; value += chr - '0'; chr = is.read(); } if (chr == '\r') { is.read(); } return value; } } |