Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Testing latest pari + WASM + node.js... and it works?! Wow.

28495 views
License: GPL3
ubuntu2004
1
\\ return one non-trivial divisor of n > 1 using Shanks's SQUFOF
2
squfof(n) =
3
{ my (p, D, d, a, b, b1, f, g, l, bb, gs);
4
if (isprime(n) || issquare(n, &n), return(n));
5
6
p = factor(n,0)[1,1];
7
if (p != n, return(p));
8
9
if (n%4==1,
10
D = n; d = sqrtint(D); b = (((d-1)\2) << 1) + 1
11
,
12
D = n << 2; d = sqrtint(D); b = (d\2) << 1
13
);
14
f = Qfb(1, b, (b^2-D)>>2);
15
l = sqrtint(d);
16
17
q = []; lq = 0; i = 0;
18
while (1,
19
i++;
20
f = qfbred(f, 1, d);
21
a = component(f, 1);
22
if (!(i%2) && issquare(a, &as),
23
my(j = 1);
24
while (j<=lq,
25
if (as == q[j], break);
26
j++
27
);
28
if (j > lq, break)
29
);
30
31
if (abs(a) <= l,
32
q = concat(q, abs(a));
33
print(q); lq++;
34
)
35
);
36
37
print("i = ", i); print(f);
38
bb = component(f, 2);
39
gs = gcd([as, bb, D]);
40
if (gs > 1, return (gs));
41
42
f = Qfb(as, -bb, as*component(f,3));
43
g = qfbred(f, 1, d);
44
b = component(g, 2);
45
until (b1 == b,
46
b1 = b; g = qfbred(g, 1, d);
47
b = component(g, 2);
48
);
49
a = abs(component(g, 1));
50
if (a % 2, a, a>>1);
51
}
52
53