File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ from itertools import permutations
2+ import math
3+
4+
5+ # 소수 판별 함수
6+ def is_prime_num (n ):
7+ if n < 2 :
8+ return False
9+ for i in range (2 , int (math .sqrt (n )) + 1 ): # n의 제곱근을 정수화 시켜준 후 + 1
10+ if n % i == 0 : # i로 나누어 떨어지면 소수가 아니므로 False 리턴
11+ return False
12+ return True # False가 리턴되지 않고 for문을 빠져나왔다면 소수이므로 True 리턴
13+
14+
15+ # 문제 해결 함수
16+ def solution (numbers ):
17+ answer = 0
18+ numbers_list = list (numbers )
19+ prime_set = set ()
20+
21+ # 모든 순열 생성
22+ for i in range (1 , len (numbers ) + 1 ):
23+ for perm in permutations (numbers_list , i ):
24+ prime_set .add (int ('' .join (perm )))
25+
26+ prime_set -= {0 , 1 } # 0 또는 1은 순열 집합에서 제거하기
27+
28+ # 순열 집합에서 소수인 값을 발견하면 +1
29+ for num in prime_set :
30+ if is_prime_num (num ):
31+ answer += 1
32+
33+ return answer
You can’t perform that action at this time.
0 commit comments