[백준] 1790번 : 수 이어 쓰기 2 - Python(파이썬)

강재원·2022년 10월 23일
0

[코딩테스트] Python

목록 보기
145/200



https://www.acmicpc.net/problem/1790

def count(t):
    num=1
    for i in range(t):
        num*=10
    return num

n,k=map(int,input().split())
t=1
num=0
r=0
e=0
while 1:
    max=(count(t)-count(t-1))*t

    if num+max>=k:
        k-=num
        r=k//t
        e=k%t
        n-=r
        break
    num+=max
    n-=count(t)-count(t-1)
    t+=1
r+=count(t-1)-1
if n<0 or n==0 and e!=0: print("-1")
elif e==0:
    m=str(r)
    print(m[len(m)-1])
else:
    r+=1
    m=str(r)
    print(m[e-1])
profile
개념정리 & 문법 정리 & 알고리즘 공부

0개의 댓글