본문 바로가기
Beakjoon&프로그래머스/파이썬

[프로그래머스/파이썬] 소수 찾기

by 현장 2022. 5. 17.

-Code

from itertools import permutations

def solution(numbers):
    cnt = 0
    nums = []
    for i in range(1, len(numbers) + 1):
        for j in permutations(numbers, i):
            s = ''
            for w in j:
                s += w
            s = int(s)
            if s >= 2:
                for k in range(2, s):
                    if s % k == 0:
                        break
                else:
                    nums.append(s)
    return len(set(nums))