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
rho1(n)=
2
{ my(x = 2,y = 5);
3
4
while(gcd(y-x,n) == 1,
5
x = (x^2+1)%n;
6
y = (y^2+1)%n; y = (y^2+1)%n
7
);
8
gcd(n, y-x);
9
}
10
11
rho2(n)=
12
{ my(m = rho1(n));
13
14
if (isprime(m), print(m), rho2(m));
15
if (isprime(n/m), print(n/m), rho2(n/m));
16
}
17
18
rho(n)=
19
{ my(m = factor(n,0));
20
21
print(m); m = m[,1]; n = m[#m];
22
if (!isprime(n), rho2(n));
23
}
24
25
rhobrent(n)=
26
{ my(x,y,x1,k,l,p,c,g);
27
28
x1 = x = y = 2;
29
k = l = p = 1;
30
c = 0;
31
while (1,
32
x=(x^2+1)%n; p=(p*(x1-x))%n;
33
c++;
34
if (c==20,
35
if (gcd(p,n)>1, break);
36
y = x; c = 0
37
);
38
k--;
39
if (!k,
40
if (gcd(p,n)>1, break);
41
42
x1 = x; k = l; l <<= 1;
43
for (j=1,k, x = (x^2+1)%n);
44
y = x; c = 0
45
)
46
);
47
until (g != 1,
48
y = (y^2+1)%n;
49
g = gcd(x1-y,n)
50
);
51
if (g==n, error("algorithm fails"));
52
g;
53
}
54
55