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 f48aa2f commit de69fb0Copy full SHA for de69fb0
866-prime-palindrome.js
@@ -0,0 +1,21 @@
1
+/**
2
+ * @param {number} N
3
+ * @return {number}
4
+ */
5
+const primePalindrome = function(N) {
6
+ if(N >= 8 && N <= 11) return 11
7
+ for(let x = 1; x < 100000; x++) {
8
+ let s = '' + x, r = s.split('').reverse().join('')
9
+ let y = +(s + r.slice(1))
10
+ if(y >= N && isPrime(y)) return y
11
+ }
12
+ return -1
13
+};
14
+
15
+function isPrime(x) {
16
+ if(x < 2 || x % 2 === 0) return x === 2
17
+ for(let i = 3; i * i <= x; i += 2) {
18
+ if(x % i === 0) return false
19
20
+ return true
21
+}
0 commit comments