Inline single-use modulo helpers
This commit is contained in:
1 parent
3598f88aaf
commit
3b8a10a20b
5 files changed
+33
-35
No files matched your search
@@ -4,20 +4,16 @@ public class MersenneNumberLucasLehmerCpuTester
|
||||
{
|
||||
public bool IsPrime(ulong exponent)
|
||||
{
|
||||
// Early rejections aligned with incremental/order sieves, but safe for small p:
|
||||
// - If 3 | p and p != 3, then 7 | M_p -> composite.
|
||||
// - If p ≡ 1 (mod 4) and p shares a factor with (p-1), reject fast.
|
||||
// - If p is divisible by divisors specific to numbers ending with 1 or 7, reject fast.
|
||||
ulong mod3 = exponent.Mod3();
|
||||
ulong mod5 = exponent.Mod5();
|
||||
ulong mod7 = exponent.Mod7();
|
||||
ulong mod11 = exponent.Mod11();
|
||||
if (
|
||||
(mod3 == 0UL && exponent != 3UL) ||
|
||||
(mod5 == 0UL && exponent != 5UL) ||
|
||||
(mod7 == 0UL && exponent != 7UL) ||
|
||||
(mod11 == 0UL && exponent != 11UL)
|
||||
)
|
||||
// Early rejections aligned with incremental/order sieves, but safe for small p:
|
||||
// - If 3 | p and p != 3, then 7 | M_p -> composite.
|
||||
// - If p ≡ 1 (mod 4) and p shares a factor with (p-1), reject fast.
|
||||
// - If p is divisible by divisors specific to numbers ending with 1 or 7, reject fast.
|
||||
if (
|
||||
(exponent.Mod3() == 0UL && exponent != 3UL) ||
|
||||
(exponent.Mod5() == 0UL && exponent != 5UL) ||
|
||||
(exponent.Mod7() == 0UL && exponent != 7UL) ||
|
||||
(exponent.Mod11() == 0UL && exponent != 11UL)
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user