n = int(input())
LIMIT = 100000
def rep_9():
tab = [[0 for _ in range(7)] for _ in range(LIMIT)]
for i in range(1, LIMIT):
tab[i] = tab[i - 1][:]
tab[i][-1] += 1
j = -1
while tab[i][j] == 9:
tab[i][j] = 0
j -= 1
tab[i][j] += 1
return tab
def to_nine(y, nine):
output = f(nine[-1], y, [])
if sum(nine[:-1]):
if nine[-2] > 1:
output = f'9[{to_nine(y, nine[:-1])}]{output}'
else:
output = f'9{y}{output}'
return output
def f(x, y, tab):
if x == 1:
if y == '[BF]':
return 'BF'
else:
return y
elif x < 10:
return f'{x}{y}'
if x % 9 == 0:
return f'9[{f(x // 9, y, tab)}]'
elif x % 8 == 0:
return f'8[{f(x // 8, y, tab)}]'
elif x % 7 == 0:
return f'7[{f(x // 7, y, tab)}]'
elif x % 6 == 0:
return f'6[{f(x // 6, y, tab)}]'
elif x % 5 == 0:
return f'5[{f(x // 5, y, tab)}]'
elif x % 4 == 0:
return f'4[{f(x // 4, y, tab)}]'
elif x % 3 == 0:
return f'3[{f(x // 3, y, tab)}]'
elif x % 2 == 0:
return f'2[{f(x // 2, y, tab)}]'
else:
temp = tab[x]
return to_nine(y, temp)
tab = rep_9()
print(f"BD", end="")
for i in range(2, n + 1):
x = f(i - 1, '[BF]', tab)
print(f"{x}B{f(i, 'D', tab)}", end="")
print(f"{f(n, 'F', tab)}")
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 | n = int(input()) LIMIT = 100000 def rep_9(): tab = [[0 for _ in range(7)] for _ in range(LIMIT)] for i in range(1, LIMIT): tab[i] = tab[i - 1][:] tab[i][-1] += 1 j = -1 while tab[i][j] == 9: tab[i][j] = 0 j -= 1 tab[i][j] += 1 return tab def to_nine(y, nine): output = f(nine[-1], y, []) if sum(nine[:-1]): if nine[-2] > 1: output = f'9[{to_nine(y, nine[:-1])}]{output}' else: output = f'9{y}{output}' return output def f(x, y, tab): if x == 1: if y == '[BF]': return 'BF' else: return y elif x < 10: return f'{x}{y}' if x % 9 == 0: return f'9[{f(x // 9, y, tab)}]' elif x % 8 == 0: return f'8[{f(x // 8, y, tab)}]' elif x % 7 == 0: return f'7[{f(x // 7, y, tab)}]' elif x % 6 == 0: return f'6[{f(x // 6, y, tab)}]' elif x % 5 == 0: return f'5[{f(x // 5, y, tab)}]' elif x % 4 == 0: return f'4[{f(x // 4, y, tab)}]' elif x % 3 == 0: return f'3[{f(x // 3, y, tab)}]' elif x % 2 == 0: return f'2[{f(x // 2, y, tab)}]' else: temp = tab[x] return to_nine(y, temp) tab = rep_9() print(f"BD", end="") for i in range(2, n + 1): x = f(i - 1, '[BF]', tab) print(f"{x}B{f(i, 'D', tab)}", end="") print(f"{f(n, 'F', tab)}") |
English