mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
Fixed O(n) runtime of "Find Largest Prime Factor" for high primes to 0(sqrt(n)).
This commit is contained in:
@@ -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);
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user