title: "[프로그래머스] 숫자 블록 Python 파이썬 해설 (Level 2) - 이도훈"
cleanUrl: "programmers/12923"
description: "프로그래머스 Level 2 문제 [숫자 블록]의 풀이를 정리합니다."
def maxdivisor(n):
if n == 1:
return 0
divisors = []
for x in range(1, int(n**0.5) + 1):
if n % x == 0:
if x <= 1e7:
divisors.append(x)
if n // x <= 1e7 and n // x != n:
divisors.append(n//x)
return max(divisors)
def solution(begin, end):
# 규칙성을 파악해보면,
# 배열의 n번째 원소는 자기 자신이 아닌 가장 큰 약수가 됨을
# 알 수 있습니다.
# 주의) 10000000까지의 숫자가 적힌 블록들을 이용했으므로,
# 자기 자신이 아니면서, 10000000 이하의 가장 큰 약수를 구해야 합니다.
answer = [maxdivisor(n) for n in range(begin, end+1)]
return answer
프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges