def repeat(*args, n=1): if n == 0: return '' args = ''.join(args) if n == 1: return args if n > 9: for m in range(9, 1, -1): if n%m == 0: return repeat( repeat(args, n=int(n//m)), n=m ) return repeat( repeat( repeat(args, n=int(n//9)), n=9 ), repeat( args, n=n%9 ), ) if len(args) == 1: return f'{n}{args}' if len(args) == 2 and n == 2: return f'{args}{args}' return f'{n}[{args}]' def solve2(n): n = int(n) # print(f'solve2({n})') if n == 0: return '' if n == 1: return 'AEC' k = int((n-2) // 2) return repeat( 'AF', repeat( solve2(k), repeat('BF', n=k), n=2 ), 'B', repeat( repeat('FD', n=n-1), 'F', repeat('B', n=n), n=n%2 ), repeat('D', n=n-1), repeat('EA', n=2*k+1), # fill repeat( repeat('C', n=k), repeat('AE', n=k-1), 'A', n=k ), repeat('E', n=k+1), repeat('C', n=2*k+2) ) if __name__ == '__main__': size = input() if 'e' in size: size = int(float(size)) else: size = int(size) solution = solve2(size) # if '.' in solution: # raise Exception('Eh....') print(solution)
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 | def repeat(*args, n=1): if n == 0: return '' args = ''.join(args) if n == 1: return args if n > 9: for m in range(9, 1, -1): if n%m == 0: return repeat( repeat(args, n=int(n//m)), n=m ) return repeat( repeat( repeat(args, n=int(n//9)), n=9 ), repeat( args, n=n%9 ), ) if len(args) == 1: return f'{n}{args}' if len(args) == 2 and n == 2: return f'{args}{args}' return f'{n}[{args}]' def solve2(n): n = int(n) # print(f'solve2({n})') if n == 0: return '' if n == 1: return 'AEC' k = int((n-2) // 2) return repeat( 'AF', repeat( solve2(k), repeat('BF', n=k), n=2 ), 'B', repeat( repeat('FD', n=n-1), 'F', repeat('B', n=n), n=n%2 ), repeat('D', n=n-1), repeat('EA', n=2*k+1), # fill repeat( repeat('C', n=k), repeat('AE', n=k-1), 'A', n=k ), repeat('E', n=k+1), repeat('C', n=2*k+2) ) if __name__ == '__main__': size = input() if 'e' in size: size = int(float(size)) else: size = int(size) solution = solve2(size) # if '.' in solution: # raise Exception('Eh....') print(solution) |