Skip to content

Commit de69fb0

Browse files
authoredMay 19, 2020
Create 866-prime-palindrome.js
1 parent f48aa2f commit de69fb0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎866-prime-palindrome.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)