숫자 블록
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
- 옛날 풀이로 안풀림
- 1개 실패뜸
def solution(begin, end):
def find(x):
if x == 1: return 0
for i in range(2,int(x**0.5)+1):
if x % i == 0:
if x // i > 10000000: continue
else: return x // i
# 소수인 경우 1 반환
return 1
arr = []
for i in range(begin,end+1):
arr.append(find(i))
return arr
- 정답 풀이
#1과 자기 자신을 제외한 가장 큰 n의 약수 구하기
from math import sqrt
def solution(begin, end):
answer = []
for i in range(begin,end+1):
if i==1:
answer.append(0)
else:
temp=[1]
for j in range(2, int(sqrt(i))+1):
if j<=10**7 and i%j==0:
temp.append(j)
if i//j<=10**7:
temp.append(i//j)
answer.append(max(temp))
return answer
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
| 📍[프로그래머스][DFS][백트래킹] 여행경로 (0) | 2024.10.07 |
|---|---|
| [프로그래머스][정렬] 가장 큰 수 (1) | 2024.10.01 |
| [프로그래머스] [union-find][bfs] 네트워크 (0) | 2024.07.15 |
| [프로그래머스][구현] 2018 카카오 [1차] 셔틀버스 (0) | 2024.06.21 |
| [프로그래머스][스택] 할인 행사 (0) | 2024.06.20 |