Skip to content

Commit 624f200

Browse files
committed
prime palindrome - lt hard - pending.
1 parent 8e9f490 commit 624f200

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# LT Hard --> Pending...
2+
# Time limit exceeded...
3+
class Solution(object):
4+
def primePalindrome(self, N):
5+
"""
6+
:type N: int
7+
:rtype: int
8+
"""
9+
10+
def isPrime(num):
11+
import math
12+
count = 0
13+
if num == 1:
14+
return False
15+
for i in range(3, int(math.ceil(math.sqrt(num)+1)), 2):
16+
if num%i == 0:
17+
count += 1
18+
if count > 0:
19+
return False
20+
return True
21+
22+
def isPalindrome(num):
23+
if str(num) == str(num)[::-1]:
24+
return True
25+
else:
26+
return False
27+
28+
while 1:
29+
if (N > 2 and N%2 != 0) or N <= 2:
30+
if isPalindrome(N):
31+
if isPrime(N):
32+
return N
33+
if N < 2 or N%2 == 0:
34+
N += 1
35+
else:
36+
N += 2
37+
38+

0 commit comments

Comments
 (0)