MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / factorWithRho

Function factorWithRho

src/compute-engine/numerics/primes.ts:286–297  ·  view source on GitHub ↗

* Complete the factorization of an odd `n ≥ 1` into `result`, using * Miller–Rabin to recognize prime cofactors and Pollard rho to split * composite ones. Callers strip the small factors first (rho is only * economical past the trial-division range).

(n: bigint, result: Map<bigint, number>)

Source from the content-addressed store, hash-verified

284 for (let c = 1n; ; c++) {
285 let x = 2n;
286 let y = 2n;
287 let ys = 2n;
288 let q = 1n;
289 let g = 1n;
290 let r = 1n;
291 while (g === 1n) {
292 x = y;
293 for (let i = 0n; i < r; i++) {
294 y = (y * y + c) % n;
295 guard();
296 }
297 for (let k = 0n; k < r && g === 1n; k += m) {
298 ys = y;
299 const lim = r - k < m ? r - k : m;
300 for (let i = 0n; i < lim; i++) {

Callers 2

primeFactorsFunction · 0.85
bigPrimeFactorsFunction · 0.85

Calls 4

isPrimeBigintFunction · 0.85
pollardRhoFunction · 0.85
setMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected