728x90
반응형
문제 출처:https://school.programmers.co.kr/learn/courses/30/lessons/136798
풀이:
시간 초과가 엄청 뜨는 코드이다
from collections import deque
def solution(number, limit, power):
st = deque([i for i in range(1,number+1)])
divisor = []
while st:
count =0
now = st.popleft()
for x in range(1, now+1):
if now % x == 0:
count +=1
divisor.append(count)
return sum([power if i >limit else i for i in divisor])
66.7 / 100
약수 구하는 곳을 다르게 표현해준다.
from collections import deque
def solution(number, limit, power):
st = deque([i for i in range(1,number+1)])
divisor = []
while st:
count =0
now = st.popleft()
for i in range(1,int(now**0.5)+1):
if now % i ==0:
count +=1
if i ** 2 != now:
count +=1
divisor.append(count)
return sum([power if i >limit else i for i in divisor])
참고
return sum([power if i >limit else i for i in divisor])
# 위 코드랑 아래 코드랑 같은코드이다
lst = []
for i in divisor:
if i > limit:
lst.append(power)
else:
lst.append(i)
return sum(lst)
반응형
댓글