values = {} def to_primes(n): if n in values: return values[n] save_n = n results = {} for i in range(2, 10): results[i] = 0 counter = 9 while n > 1 and counter > 1: if n % counter == 0: results[counter] += 1 n = n//counter else: counter -= 1 if counter == 1: return None values[save_n] = results return results def split_number(value, string): if value == 0: return "" if value == 1: return string if len(string) == 1 else string[1:-1] if value < 10: return f"{value}{string}" res = None for i in range(1000): res = to_primes(value - i) if res: break result = string for k, v in res.items(): for i in range(v): result = f"{k}[{result}]" if i > 0: result += f"{i}[{string}]" return result def to_9_sys(value, string, origin=True): # if origin and value > 9: # res = to_primes(value) # if res: # print(res) result = "" if value == 0: return "" if value == 1: return string if len(string) == 1 else string[1:-1] mod = value%9 if x:=to_9_sys(value//9, string, False): result = f"9[{x}]" if mod: result += f"{mod}{string}" return result def draw_triangle_2(n): result = "" for k in range(n): if k % 2 == 0: result += to_9_sys(n - k - 1, "[AEAC]") + "AE" else: result += "E" + to_9_sys(n - k - 1, "[CE]") return result def draw_triangle(n): if n == 1: return "AE" if n == 0: return "" result = "" if n < 10: return draw_triangle_2(n) side = (n+1)//2 # result += f"{n//2}[{side}A{side-1}[EC]E]{side}A{n//2}C" + draw_triangle(n//2) result = to_9_sys(n//2, f"[{to_9_sys(side, 'A')}{to_9_sys(side-1, '[EC]')}E]") + to_9_sys(side, 'A') result += to_9_sys(n//2, 'C') + draw_triangle(n//2) result += f"{to_9_sys(side-1, '[EC]')}E" + draw_triangle((n-1)//2) # result += f"{side-1}[EC]E" + draw_triangle((n-1)//2) return result def main(): n = int(input()) # print(to_9_sys(n, "A")) # result = draw_triangle_2(n) + split_number(n, "C") result1 = draw_triangle(n) + to_9_sys(n, "C") # print(len(result), len(result1)) print(result1) # print((values)) # print(split_number(n, ['AD'])) # print(to_9_sys(n, ['AD'])) if __name__ == '__main__': 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 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 | values = {} def to_primes(n): if n in values: return values[n] save_n = n results = {} for i in range(2, 10): results[i] = 0 counter = 9 while n > 1 and counter > 1: if n % counter == 0: results[counter] += 1 n = n//counter else: counter -= 1 if counter == 1: return None values[save_n] = results return results def split_number(value, string): if value == 0: return "" if value == 1: return string if len(string) == 1 else string[1:-1] if value < 10: return f"{value}{string}" res = None for i in range(1000): res = to_primes(value - i) if res: break result = string for k, v in res.items(): for i in range(v): result = f"{k}[{result}]" if i > 0: result += f"{i}[{string}]" return result def to_9_sys(value, string, origin=True): # if origin and value > 9: # res = to_primes(value) # if res: # print(res) result = "" if value == 0: return "" if value == 1: return string if len(string) == 1 else string[1:-1] mod = value%9 if x:=to_9_sys(value//9, string, False): result = f"9[{x}]" if mod: result += f"{mod}{string}" return result def draw_triangle_2(n): result = "" for k in range(n): if k % 2 == 0: result += to_9_sys(n - k - 1, "[AEAC]") + "AE" else: result += "E" + to_9_sys(n - k - 1, "[CE]") return result def draw_triangle(n): if n == 1: return "AE" if n == 0: return "" result = "" if n < 10: return draw_triangle_2(n) side = (n+1)//2 # result += f"{n//2}[{side}A{side-1}[EC]E]{side}A{n//2}C" + draw_triangle(n//2) result = to_9_sys(n//2, f"[{to_9_sys(side, 'A')}{to_9_sys(side-1, '[EC]')}E]") + to_9_sys(side, 'A') result += to_9_sys(n//2, 'C') + draw_triangle(n//2) result += f"{to_9_sys(side-1, '[EC]')}E" + draw_triangle((n-1)//2) # result += f"{side-1}[EC]E" + draw_triangle((n-1)//2) return result def main(): n = int(input()) # print(to_9_sys(n, "A")) # result = draw_triangle_2(n) + split_number(n, "C") result1 = draw_triangle(n) + to_9_sys(n, "C") # print(len(result), len(result1)) print(result1) # print((values)) # print(split_number(n, ['AD'])) # print(to_9_sys(n, ['AD'])) if __name__ == '__main__': main() |