feat: adicionando solução do 5° desafio

This commit is contained in:
Ana Carolina Duarte Cavalcante 2022-10-23 09:52:13 -03:00
parent 6738f84bbd
commit 61c0db0656

View File

@ -16,6 +16,26 @@
*/ */
function isPrime(number) { function isPrime(number) {
// implementar logica aqui // implementar logica aqui
if (number === 2 || number === 3) return true
if (number % 2 === 0 || number < 2) return false
var s = 0,
d = number - 1
while ((d & 1) == 0) {
d >>= 1
++s
}
let base = 2
var x = Math.pow(base, d) % number
if (x == 1 || x == number - 1) return true
for (var i = 1; i <= s; i++) {
x = (x * x) % number
if (x === number - 1) return true
}
return false return false
} }