-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem003.js
More file actions
33 lines (29 loc) · 742 Bytes
/
Copy pathproblem003.js
File metadata and controls
33 lines (29 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function problem003(target) {
let lastFactor = 1;
if(target % 2 === 0) {
lastFactor = 2;
target = target / 2;
while(n % 2 === 0){
target = target / 2;
}
}
let factor = 3;
let maxFactor = Math.sqrt(target);
while(target > 1 && factor <= maxFactor) {
if(target % factor === 0) {
target = target / factor;
lastFactor = factor;
while(target % factor === 0) {
target = target / factor;
}
maxFactor = Math.sqrt(target);
}
factor = factor + 2;
}
if(target === 1) {
return lastFactor;
} else {
return target;
}
}
module.exports = problem003;