백준
백준 2023번: 신기한 소수
2호0
2023. 2. 10. 19:57
https://www.acmicpc.net/problem/2023
2023번: 신기한 소수
수빈이가 세상에서 가장 좋아하는 것은 소수이고, 취미는 소수를 가지고 노는 것이다. 요즘 수빈이가 가장 관심있어 하는 소수는 7331이다. 7331은 소수인데, 신기하게도 733도 소수이고, 73도 소수
www.acmicpc.net
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
|
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline
n = int(input())
def isPrime(num):
for i in range(2, int(num/2+1)):
if num % i==0:
return False
return True
def DFS(number):
if len(str(number))==n:
print(number)
else:
for i in range(1,10,2):
if i%2 == 0:
continue
if isPrime(number*10+i):
DFS(number*10+i)
DFS(2)
DFS(3)
DFS(5)
DFS(7)
|
cs |