💻 하나씩 차곡차곡/프로그래머스 (Python)
[프로그래머스/python/Lv1] 소수 만들기
뚜루리
2023. 12. 23. 09:45
728x90
320x100
from itertools import combinations
def solution(nums):
answer = 0
numList = list(combinations(nums,3))
sosuCnt = 0
for i in numList:
sumNum = sum(i)
for j in range(1, sumNum+1):
if sumNum % j == 0:
sosuCnt += 1
if sosuCnt == 2:
answer += 1
sosuCnt = 0
return answer
- 1. 중복이 불가능하고 순서가 있는 함수인 combinations를 사용하여 3가지 수의 리스트를 만들어 줌
- 2. 3가지의 합의 소수를 판별하고 소수인 경우 answer 의 카운트를 올려준다.
728x90
320x100