mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 09:43:54 +01:00
Fixed O(n) runtime of "Find Largest Prime Factor" for high primes to 0(sqrt(n)).
This commit is contained in:
parent
a2551f98c2
commit
086fc67ecc
@ -65,16 +65,15 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
solver: (data: number, ans: string) => {
|
||||
let fac: number = 2;
|
||||
let n: number = data;
|
||||
while (n > fac) {
|
||||
if (n % fac === 0) {
|
||||
while (Math.sqrt(n) > fac-1) {
|
||||
while (n % fac === 0) {
|
||||
n = Math.round(n / fac);
|
||||
fac = 2;
|
||||
} else {
|
||||
++fac;
|
||||
}
|
||||
}
|
||||
|
||||
return fac === parseInt(ans, 10);
|
||||
return (n===1?(fac-1):n) === parseInt(ans, 10);
|
||||
},
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user