-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathphiP.gp
54 lines (45 loc) · 1.75 KB
/
phiP.gp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
largest_primefactor(n) = vecmax(factorint(n)~[1,])
/* We examine P values with eulerphi(P) in [mini, maxi],
maxi = mini + multphi*(len - 1) */
/* We assume that P is divisible by multP and that
phiP and mini are divisible my multphi, so the array
entry phi[i] contains a P such that phiP = eulerphi(P) and
(phiP - mini) / multphi + 1 = i. (phi[i] contains zero if no such
P was found). Conversely, phiP = (i - 1) * multphi + mini */
/* mini = 150000000; */
/* len = 10000000; */
/* multP = 3*5*7*11; */
make_phiP (mini, len, multP, oldbest) =
{
local (multphi, maxi, phi, P, phiP, best, multP2);
multphi = eulerphi(multP);
best = oldbest;
if (mini % multphi != 0,
error("mini = ", mini, " is not a multiple of multphi = ", multphi));
maxi = mini + multphi * (len - 1);
phi = vector(len);
/* For each candidate odd P value < 4*maxi and a multiple of multP,
if eulerphi(P) is in the [mini, maxi] range, store the P value at
phi[i] with i = (eulerphi(P) - mini) / multphi + 1 */
multP2 = 2*multP;
P = 3*multP;
while (P < maxi*4,
phiP = eulerphi(P);
if (phiP % multphi != 0,
error("phiP = ", phiP, " is not a multiple of multphi = ", multphi)
);
if (mini <= phiP && phiP <= maxi, phi[(phiP - mini) / multphi + 1] = P);
P += multP2;
);
/* Go through the array and report large P, P/phi(P) combinations.
best contains the maximal value of P * phiP seen so far */
for (i = 1, len,
P = phi[i];
phiP = (i - 1) * multphi + mini;
if (P * phiP > best * 1.05 && largest_primefactor(phiP) <= 19,
print(P, " = ", factorint(P), ", ", phiP, " = ", factorint(phiP), " P/phi(P) = ", 1. * P / phiP, " ", 1. * P * phiP / best);
best = P * phiP
);
);
return (best);
}