Skip to content

Commit 754487f

Browse files
iakgoogSutthinart Khunvadhana
and
Sutthinart Khunvadhana
authored
Fix Euler Problem 3 (#506)
* Fix Euler Problem 3 * Fix indentation Co-authored-by: Sutthinart Khunvadhana <[email protected]>
1 parent be96654 commit 754487f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Project-Euler/Problem3.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// https://projecteuler.net/problem=3
2+
const problem = 600851475143
3+
4+
const largestPrime = (num) => {
5+
let newnumm = num
6+
let largestFact = 0
7+
let counter = 2
8+
while (counter * counter <= newnumm) {
9+
if (newnumm % counter === 0) {
10+
newnumm = newnumm / counter
11+
} else {
12+
counter++
13+
}
14+
}
15+
if (newnumm > largestFact) {
16+
largestFact = newnumm
17+
}
18+
return largestFact
19+
}
20+
console.log(largestPrime(problem))

0 commit comments

Comments
 (0)