Skip to content

Instantly share code, notes, and snippets.

@hassaku63
Created June 21, 2020 14:23
Show Gist options
  • Save hassaku63/b4a56bd8c370b712abce8154f26e5d13 to your computer and use it in GitHub Desktop.
Save hassaku63/b4a56bd8c370b712abce8154f26e5d13 to your computer and use it in GitHub Desktop.
# wrong answer...
import string
# 1千兆 + 1
N = int(input())
n_digits = len(str(1000000000000001))
letters = string.ascii_lowercase
x = N - 1
ans = []
while True:
mod = x % 26
ans = [ mod ] + ans
x = x // 26 - 1
if x <= 0:
if ans[0] == 0:
ans = [0] + ans
break
# print(ans)
print("".join([ letters[v] for v in ans ]))
@hassaku63
Copy link
Author

正解例

import string

# 1千兆 + 1
N = int(input())
n_digits = len(str(1000000000000001))
letters = string.ascii_lowercase

x = N - 1
ans = []

while True:
    mod = x % 26
    div = x // 26
    
    ans.append(mod)
    if div == 0:
        break
    x = div - 1

ans = ans[::-1]
# print(ans)
print("".join([ letters[v] for v in ans ]))

@hassaku63
Copy link
Author

修正

import string

# 1千兆 + 1
N = int(input())
n_digits = len(str(1000000000000001))
letters = string.ascii_lowercase

x = N
ans = []
while True:
    x -= 1
    mod = x % 26
    x = x // 26
    
    ans.append(mod)
    if x == 0:
        break

ans = ans[::-1]
print("".join([ letters[v] for v in ans ]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment