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 |
'백준' 카테고리의 다른 글
백준 2343번: 기타 레슨 (0) | 2023.02.16 |
---|---|
백준 1167번: 트리의 지름 (0) | 2023.02.12 |
백준 1517번: 버블 소트 (0) | 2023.02.09 |
백준 13023번: ABCDE (0) | 2023.02.09 |
백준 11004번: K번째 수 (0) | 2023.02.06 |