반응형
https://programmers.co.kr/learn/courses/30/lessons/12977
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr

1. combinations으로 숫자 세 개 뽑기
2. 뽑은 세 개의 숫자를 합한 값이 소수인지 판별하기.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
import math | |
def solution(nums): | |
candidates = combinations(nums, 3) | |
answer = 0 | |
for item in candidates: | |
sums = sum(item) | |
is_prime = True | |
for i in range(2, int(math.sqrt(sums)) + 1): | |
if sums % i == 0: | |
is_prime = False | |
break | |
if is_prime: | |
answer += 1 | |
return answer | |
반응형
'프로그래밍 > 코딩테스트 문제풀이' 카테고리의 다른 글
[Python] 백준 15684. 사다리 조작 (0) | 2020.05.18 |
---|---|
[Python] 백준 11003. 최솟값 찾기 (0) | 2020.05.16 |
[Python] 프로그래머스. 점프와 순간이동 (Level 2) (0) | 2020.05.08 |
[Python] 백준 17822. 원판 돌리기 (0) | 2020.05.07 |
[Python] 프로그래머스. 타일 장식물 (Level 3) (0) | 2020.05.06 |