#mój kod z finału oij, bo brak czasu na robienie A a może jakies punkty będą import sys def findMultiply(x): najblizsza = [float('inf'), -1, -1] for i in range(1, 10): for j in range(1, 10): a = x - (i * j) if 0 <= a < najblizsza[0]: najblizsza[0] = a najblizsza[1] = i najblizsza[2] = j return (najblizsza[0], najblizsza[1], najblizsza[2]) def generateFromMultiply(x, pos1, pos2, dest, add): ans = f"{pos1}[{pos2}{dest}]" # breakpoint() if x > 1: if x < 10: ans += str(x) + dest else: g = findMultiply(x) ans += generateFromMultiply(g[0], g[1], g[2], dest, add) elif x == 1: if not add: ans += dest else: ans += f"1{dest}" return ans def main(): n = int(sys.stdin.readline()) if n == 1: print("FBD") sys.exit() if n < 10: ans = f"{n}F{n}B" for i in range(n-1, 0, -1): if i != 1: ans += f"D{i}E{i}[AC]" else: ans += "DEACD" print(ans) sys.exit() if n >= 10: g = findMultiply(n) ans = str(generateFromMultiply(g[0], g[1], g[2], 'F', False)) + str(generateFromMultiply(g[0], g[1], g[2], 'B', False)) for i in range(n-1, 0, -1): if i < 10: if i != 1: ans += f"D{i}E{i}[AC]" else: ans += "DEACD" else: g = findMultiply(i) ans += "D" + str(generateFromMultiply(g[0], g[1], g[2], 'E', False)) + str(generateFromMultiply(g[0], g[1], g[2], "[AC]", True)) print(ans) sys.exit() 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 | #mój kod z finału oij, bo brak czasu na robienie A a może jakies punkty będą import sys def findMultiply(x): najblizsza = [float('inf'), -1, -1] for i in range(1, 10): for j in range(1, 10): a = x - (i * j) if 0 <= a < najblizsza[0]: najblizsza[0] = a najblizsza[1] = i najblizsza[2] = j return (najblizsza[0], najblizsza[1], najblizsza[2]) def generateFromMultiply(x, pos1, pos2, dest, add): ans = f"{pos1}[{pos2}{dest}]" # breakpoint() if x > 1: if x < 10: ans += str(x) + dest else: g = findMultiply(x) ans += generateFromMultiply(g[0], g[1], g[2], dest, add) elif x == 1: if not add: ans += dest else: ans += f"1{dest}" return ans def main(): n = int(sys.stdin.readline()) if n == 1: print("FBD") sys.exit() if n < 10: ans = f"{n}F{n}B" for i in range(n-1, 0, -1): if i != 1: ans += f"D{i}E{i}[AC]" else: ans += "DEACD" print(ans) sys.exit() if n >= 10: g = findMultiply(n) ans = str(generateFromMultiply(g[0], g[1], g[2], 'F', False)) + str(generateFromMultiply(g[0], g[1], g[2], 'B', False)) for i in range(n-1, 0, -1): if i < 10: if i != 1: ans += f"D{i}E{i}[AC]" else: ans += "DEACD" else: g = findMultiply(i) ans += "D" + str(generateFromMultiply(g[0], g[1], g[2], 'E', False)) + str(generateFromMultiply(g[0], g[1], g[2], "[AC]", True)) print(ans) sys.exit() main() |