Written by
최태열
on
on
[Python][프로그래머스][Level4] 숫자 블록
[Python][프로그래머스][Level4] 숫자 블록
코드
import math
def solution(begin, end):
answer=[]
for i in range(begin,end+1):
for j in range(2,int(math.sqrt(i))+1):
if i%j==0 and i//j<10**7:
answer.append(i//j)
break
else:
answer.append(1)
return answer if begin!=1 else [0]+answer[1:]
1 번째 블록은 0이고
소수자리의 블록은 1이고
다른 자리는 자신을 제외한 약수중 가장 큰 값이다.
따라서 해당 수가 N이라 했을때,
2부터 N의 제곱근까지중 나눠지는 값을 숫자블록에 대입한다.
Discussion and feedback