From ab86fc16fe277d60cc16f0bbdf3711a59b3ab023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Lema=C5=84czyk?= Date: Thu, 16 Oct 2025 22:01:34 +0200 Subject: [PATCH] Fix quotient and remainder calculation in factor extraction --- PerfectNumbers.Core/PrimeOrderCalculator.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PerfectNumbers.Core/PrimeOrderCalculator.cs b/PerfectNumbers.Core/PrimeOrderCalculator.cs index 1f205cd..deebe72 100644 --- a/PerfectNumbers.Core/PrimeOrderCalculator.cs +++ b/PerfectNumbers.Core/PrimeOrderCalculator.cs @@ -1205,11 +1205,12 @@ internal static partial class PrimeOrderCalculator continue; } - // Use DivRem to reuse a single division for the quotient and remainder. + // Derive the remainder from the quotient to avoid an extra division. int exponent = 0; while (true) { - ulong quotient = Math.DivRem(remainingLocal, primeCandidate, out ulong divisionRemainder); + ulong quotient = remainingLocal / primeCandidate; + ulong divisionRemainder = remainingLocal - (quotient * primeCandidate); if (divisionRemainder != 0UL) { break;