일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 조합
- lv4
- programmers
- cte
- 시간복잡도
- itertools
- python
- Level2
- 프로그래머스
- 코딩테스트
- 코테
- Queue
- 코딩
- 연습문제
- Stack
- 완전탐색
- 데이터분석
- import re
- coding
- tableau
- coding test
- time complexity
- BFS
- mysql
- lambda
- collections
- sql
- level4
- 파이썬
- counter
- Today
- Total
ror_coding
[Programmers] 소수 만들기 - 12977 본문
728x90
조합 후 소수가 되는 경우 개수길래 set(조합해서 나온 수) 을 해서 중복을 방지했는데 .. 중복 허용인가보다 ㅎㅎ set을 빼니 맞았다.
Question
주어진 숫자 중 3개의 수를 더했을 때 소수가 되는 경우의 개수를 구하려고 합니다. 숫자들이 들어있는 배열 nums가 매개변수로 주어질 때, nums에 있는 숫자들 중 서로 다른 3개를 골라 더했을 때 소수가 되는 경우의 개수를 return 하도록 solution 함수를 완성해주세요.
Code
from itertools import combinations as comb
def solution(nums):
answer = 0
sums = [sum(c) for c in comb(nums,3)]
for n in sums:
if not sum(1 for i in range(2,int(n**0.5)+1) if n%i==0):
answer += 1
return answer

now me
On my github
728x90
'Algorithm > Python' 카테고리의 다른 글
[Programmers] 실패율 - 42889 (1) | 2024.10.12 |
---|---|
[Programmers] 소수 찾기 - 12921 (0) | 2024.10.12 |
[Programmers] 모의고사 - 42840 (0) | 2024.10.12 |
[Programmers] [1차] 비밀지도 - 17681 (0) | 2024.10.12 |
[Programmers] 가장 가까운 같은 글자 - 142086 (0) | 2024.10.12 |