알고리즘/수학 1
백준 2501 python
자코린이
2023. 6. 29. 01:23
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