https://programmers.co.kr/learn/courses/30/lessons/12923
✅ Solution
- 자기 자신을 제외한 최대 약수가 답이다.
- 주의할 점은 길이는 1,000,000,000인 도로지만 들어가는 수의 최댓값은 10,000,000 이므로 최대 약수를 구할 때, 10,000,000을 넘지 않는다는 조건을 추가한다.
✅ Code
def divisior(num):
if num == 1:
return 0
else:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
if (num // i) <= 10000000:
return num // i
return 1
def solution(begin, end):
answer = []
for i in range(begin, end + 1):
answer.append(divisior(i))
return answer
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] Level 2 - N개의 최소공배수 (Python) (0) | 2022.06.30 |
---|---|
[프로그래머스] Level 2 - N-Queen (Python) (0) | 2022.06.30 |
[프로그래머스] Level 2 - 땅따먹기 (Python) (0) | 2022.06.28 |
[프로그래머스] Level 2 - 스킬 트리 (Python) (0) | 2022.06.27 |
[프로그래머스] Level 2 - 방문 길이 (Python) (0) | 2022.06.27 |