mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Release calc version 2.10.3t5.45
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1995 David I. Bell
|
||||
* Copyright (c) 1997 David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
*
|
||||
@@ -19,26 +19,19 @@ define mersenne(p)
|
||||
return 1;
|
||||
|
||||
/* if p is not prime, then 2^p-1 is not prime */
|
||||
if (! ptest(p,10))
|
||||
if (! ptest(p,1))
|
||||
return 0;
|
||||
|
||||
/* calculate 2^p-1 for later mods */
|
||||
p_mask = 2^p - 1;
|
||||
|
||||
/* lltest: u(i+1) = u(i)^2 - 2 mod 2^p-1 */
|
||||
u = 4;
|
||||
for (i = 2; i < p; ++i) {
|
||||
u = u^2 - 2;
|
||||
u = u&p_mask + u>>p;
|
||||
if (u > p_mask)
|
||||
u = u&p_mask + 1;
|
||||
u = hnrmod(u^2 - 2, 1, p, -1);
|
||||
}
|
||||
|
||||
/* 2^p-1 is prime iff u(p) = 0 mod 2^p-1 */
|
||||
return (u == p_mask);
|
||||
return (u == 0);
|
||||
}
|
||||
|
||||
global lib_debug;
|
||||
if (lib_debug >= 0) {
|
||||
if (config("lib_debug") >= 0) {
|
||||
print "mersenne(p) defined";
|
||||
}
|
||||
|
Reference in New Issue
Block a user