diff --git a/PerfectNumbers.Core/PrimeOrderCalculator.Cpu.cs b/PerfectNumbers.Core/PrimeOrderCalculator.Cpu.cs index ac490dc..91078ef 100644 --- a/PerfectNumbers.Core/PrimeOrderCalculator.Cpu.cs +++ b/PerfectNumbers.Core/PrimeOrderCalculator.Cpu.cs @@ -855,13 +855,6 @@ internal static partial class PrimeOrderCalculator { while (compositeStack.Count > 0) { - long currentTimestamp = Stopwatch.GetTimestamp(); - if (currentTimestamp > deadlineTimestamp) - { - pollardRhoDeadlineReached = true; - break; - } - ulong composite = compositeStack.Pop(); // composite will never be smaller than 1 on the execution path // if (composite <= 1UL) @@ -877,6 +870,14 @@ internal static partial class PrimeOrderCalculator continue; } + long currentTimestamp = Stopwatch.GetTimestamp(); + if (currentTimestamp > deadlineTimestamp) + { + pollardRhoDeadlineReached = true; + pending.Add(new PendingEntry(composite, knownComposite: true)); + continue; + } + if (!TryPollardRho(composite, deadlineTimestamp, out ulong factor)) { pending.Add(new PendingEntry(composite, knownComposite: true));