문제
코드
def get_num_divisor(num: int) -> int:
divisor_num = 0
for i in range(1, int(num ** (1 / 2)) + 1):
if (num % i == 0):
divisor_num += 1
if ((i ** 2) != num):
divisor_num += 1
return divisor_num
def solution(number: int, limit: int, power: int) -> int:
answer = 0
for x in range(1, number+1):
divisor_num = get_num_divisor(x)
if divisor_num <= limit:
answer += divisor_num
else:
answer += power
return answer
if __name__ == '__main__':
print(solution(5, 3, 2))
print(solution(10, 3, 2))
결과
출처 & 깃허브
프로그래머스
깃허브