ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 25821 |
문제명 | Palindromic Primes |
레벨 | 플래티넘 2 |
분류 |
정수론 |
시간복잡도 | O(sqrt(n) * logn) |
인풋사이즈 | n<=10^12 |
사용한 언어 | Python 3.11 |
제출기록 | 33376KB / 5976ms |
최고기록 | 2804ms |
해결날짜 | 2023/03/31 |
"""Solution code for "BOJ 25821. Palindromic Primes".
- Problem link: https://www.acmicpc.net/problem/25821
- Solution link: http://www.teferi.net/ps/problems/boj/25821
Tags: [Math] [Number theory]
"""
from teflib import numtheory
def main():
L, H = [int(x) for x in input().split()]
answer = 0
if L <= 2 <= H:
answer += 1
if L <= 11 <= H:
answer += 1
beg = size = 1
while beg * size <= H:
for i in range(beg, beg + size):
s = str(i)
n = int(s + s[-2::-1])
if L <= n <= H and numtheory.is_prime(n):
answer += 1
beg += size * 2
if beg > size * 10:
beg = size = size * 10
print(answer)
if __name__ == '__main__':
main()