def compress(rep, dir): if rep >= 10: div = 9 for m in range(5, 10): if rep % m == 0: div = m b = "{}[{}]".format(div, compress(rep // div, dir)) else: b = "" div = 10 if rep % div > 1: if len(dir) > 1: b += "{}[{}]".format(rep % div, dir) else: b += "{}{}".format(rep % div, dir) elif rep % div == 1: b += dir return b def triangle(n): if n == 1: return "A" if n == 2: return "AEACA" if n == 3: return "A2FD2BF2DB2A" if n == 4: return "A3FD3BF3DBA2E2A2C2A" n -= 1 w = n // 2 ret = "AEAE" if n % 2 == 1 else "AE" ret += "2[" + triangle(w) + "]" ret += compress(w, "CAC2E") if n % 2 == 1 else compress(w, "CE") ret += compress(w, "F") sq1 = compress(w - 1, "DB") + "D" sq2 = compress(w, "F") ret += compress(w - 1, sq1 + sq2) + sq1 ret += compress(w, "B") ret += (compress(w - 1, "CAC2E") + "CACEC") if n % 2 == 1 else (compress(w - 1, "CE") + "C") ret += compress(n, "A") return ret def main(): n = int(input()) r = triangle(n) + compress(n, "E") + compress(n, "C") print(r) main()
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 | def compress(rep, dir): if rep >= 10: div = 9 for m in range(5, 10): if rep % m == 0: div = m b = "{}[{}]".format(div, compress(rep // div, dir)) else: b = "" div = 10 if rep % div > 1: if len(dir) > 1: b += "{}[{}]".format(rep % div, dir) else: b += "{}{}".format(rep % div, dir) elif rep % div == 1: b += dir return b def triangle(n): if n == 1: return "A" if n == 2: return "AEACA" if n == 3: return "A2FD2BF2DB2A" if n == 4: return "A3FD3BF3DBA2E2A2C2A" n -= 1 w = n // 2 ret = "AEAE" if n % 2 == 1 else "AE" ret += "2[" + triangle(w) + "]" ret += compress(w, "CAC2E") if n % 2 == 1 else compress(w, "CE") ret += compress(w, "F") sq1 = compress(w - 1, "DB") + "D" sq2 = compress(w, "F") ret += compress(w - 1, sq1 + sq2) + sq1 ret += compress(w, "B") ret += (compress(w - 1, "CAC2E") + "CACEC") if n % 2 == 1 else (compress(w - 1, "CE") + "C") ret += compress(n, "A") return ret def main(): n = int(input()) r = triangle(n) + compress(n, "E") + compress(n, "C") print(r) main() |