
input_int, key = map(int, input().split())
result = []
for i in range(1, input_int+1):
if input_int % i == 0:
result.append(i)
if len(result) > key - 1:
print(result[key - 1])
else:
print(0)
코드 결과는 메모리가 더 작지만, 시간이 4ms 더 길게 나왔습니다.
아래 분의 코드를 사용하면 시간이 44ms로 더 작습니다.
https://computer-science-student.tistory.com/574
[파이썬, Python] 백준 2501번 : 약수 구하기
백준 2501번 : 약수 구하기 (문제 바로가기) 내 코드 N, K = map(int, input().split()) result = 0 for i in range(1, N + 1): if N % i == 0: K -= 1 if K == 0: result = i break print(result)
computer-science-student.tistory.com
'알고리즘 > 수학 1' 카테고리의 다른 글
백준 2720 python (0) | 2023.06.26 |
---|---|
백준 2903 python (0) | 2023.06.25 |