mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-20 02:23:24 +08:00
Fix Euler Problem 3 (#506)
* Fix Euler Problem 3 * Fix indentation Co-authored-by: Sutthinart Khunvadhana <sutthinart.khunvadhana@refinitiv.com>
This commit is contained in:

committed by
GitHub

parent
be96654b87
commit
754487f1e1
20
Project-Euler/Problem3.js
Normal file
20
Project-Euler/Problem3.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// https://projecteuler.net/problem=3
|
||||||
|
const problem = 600851475143
|
||||||
|
|
||||||
|
const largestPrime = (num) => {
|
||||||
|
let newnumm = num
|
||||||
|
let largestFact = 0
|
||||||
|
let counter = 2
|
||||||
|
while (counter * counter <= newnumm) {
|
||||||
|
if (newnumm % counter === 0) {
|
||||||
|
newnumm = newnumm / counter
|
||||||
|
} else {
|
||||||
|
counter++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newnumm > largestFact) {
|
||||||
|
largestFact = newnumm
|
||||||
|
}
|
||||||
|
return largestFact
|
||||||
|
}
|
||||||
|
console.log(largestPrime(problem))
|
Reference in New Issue
Block a user