| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 1990 |
| 문제명 | 소수인팰린드롬 |
| 레벨 | 골드 5 |
| 분류 |
정수론 |
| 시간복잡도 | O(sqrt(n) * logn) |
| 인풋사이즈 | n<=10^8 |
| 사용한 언어 | Python 3.11 |
| 제출기록 | 33376KB / 64ms |
| 최고기록 | 36ms |
| 해결날짜 | 2023/03/31 |
"""Solution code for "BOJ 1990. 소수인팰린드롬".
- Problem link: https://www.acmicpc.net/problem/1990
- Solution link: http://www.teferi.net/ps/problems/boj/1990
Tags: [Number theory]
"""
from teflib import numtheory
def main():
a, b = [int(x) for x in input().split()]
for x in (5, 7, 11):
if a <= x <= b:
print(x)
beg = size = 10
while beg * size <= b:
for i in range(beg, beg + size):
s = str(i)
n = int(s + s[-2::-1])
if a <= n <= b and numtheory.is_prime(n):
print(n)
beg += size * 2
if beg > size * 10:
beg = size = size * 10
print('-1')
if __name__ == '__main__':
main()
"""Solution code for "BOJ 1990. 소수인팰린드롬".
- Problem link: https://www.acmicpc.net/problem/1990
- Solution link: http://www.teferi.net/ps/problems/boj/1990
Tags: [Number theory]
"""
from teflib import numtheory
MAX_NUM = 10_000_000
def main():
a, b = [int(x) for x in input().split()]
for p in numtheory.prime_list(a, min(b, MAX_NUM)):
p = str(p)
if p[::-1] == p:
print(p)
print('-1')
if __name__ == '__main__':
main()