protected override FactorizationResult Process(BigInteger n, BigInteger p, BigInteger q, int coefficient, CancellationToken cancellationToken) { p = p * coefficient; q = n - p; BigInteger d; do { d = BigIntegerExtentions.GreatestCommonDivisor(p, q); if (d > 1) { continue; } p--; q++; } while (d == 1 && !cancellationToken.IsCancellationRequested); return(cancellationToken.IsCancellationRequested ? FactorizationResult.Failed : new FactorizationResult(d, n / d)); }
protected override FactorizationResult Process(BigInteger n, int threadNumber, int threadCount, CancellationToken cancellationToken) { for (BigInteger z = n.Sqtr() + threadCount; !cancellationToken.IsCancellationRequested; z += threadNumber) { BigInteger p = BigInteger.ModPow(z, 2, n); if (!p.IsFullSquare()) { continue; } BigInteger q = BigIntegerExtentions.GreatestCommonDivisor(z - p.Sqtr(), n); if (q > 1) { return(new FactorizationResult(q, n / q)); } } return(FactorizationResult.Failed); }