2018 KAKAO BLIND RECRUITMENT - N진수 게임 (Level 2)

 

https://programmers.co.kr/learn/courses/30/lessons/17687


Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def solution(n, t, m, p):
    def convertor(val, n):
        rst = ''
        while True:
            val, r = val//n, dic[val%n]
            rst = f"{r}{rst}"
            if val < n:
                return f"{dic[val]}{rst}" if val > 0 else rst

    dic = list('0123456789ABCDEF')
    ser = ""
    rst = ""

    val = 0
    idx = p-1
    for _ in range(t):
        while len(ser) < idx+1:
            ser = f"{ser}{convertor(val, n)}"
            val += 1
        rst = f"{rst}{ser[idx]}"
        idx += m
    return rst

Complexity

$O(t \times ?)$