#866

Prime Palindrome

expert · 1195 · lc medium +32 · verified · 28% accepted · 517 likes · top 6%

Description

Given a positive integer n, return the smallest prime palindrome that is greater than or equal to n.

A prime has exactly two divisors: 1 and itself. Note that 1 is not prime.

- Examples of primes: 2, 3, 5, 7, 11, 13.

A palindrome reads the same forwards and backwards.

- Examples of palindromes: 101, 12321.

The answer is guaranteed to exist and fall within [2, 2 * 108].

Example 1:

Input: n = 6
Output: 7

Example 2:

Input: n = 8
Output: 11

Example 3:

Input: n = 13
Output: 101

Code

1
2
3