We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8e9f490 commit 624f200Copy full SHA for 624f200
ProblemSolving/primePalindrome/prime.py
@@ -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
20
+ return True
21
22
+ def isPalindrome(num):
23
+ if str(num) == str(num)[::-1]:
24
25
+ else:
26
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
36
+ N += 2
37
38
0 commit comments