File: Selfridge.gp

package info (click to toggle)
wims 2%3A4.29a%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 185,704 kB
  • sloc: xml: 366,687; javascript: 120,570; ansic: 62,341; java: 62,170; sh: 7,744; perl: 3,937; yacc: 3,217; cpp: 1,915; lex: 1,805; makefile: 1,084; lisp: 914; pascal: 601; python: 520; php: 318; asm: 7
file content (72 lines) | stat: -rw-r--r-- 2,157 bytes parent folder | download | duplicates (9)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

!! Selfridge check for primes.
!! Checks primes > 500 000, for otherwise it is in prime table.

!set Selfridge_src=Selfridge_table=vector(1000,x,0);\
\
{ Selfridge_check(x)=if(abs(x)<500000,return(1));\
  Selfridge_f=factor(x-1);Selfridge_n=matsize(Selfridge_f)[1];\
  for(Selfridge_k=1,Selfridge_n,\
    Selfridge_p=Selfridge_f[Selfridge_k,1];\
    if(Selfridge_p>=500000,\
      if(Selfridge_ptr>=999,return(-1));\
      Selfridge_ptr++; Selfridge_table[Selfridge_ptr]=Selfridge_p;\
    );\
    Selfridge_t=0;for(Selfridge_j=2,1000,\
      if(Mod(Selfridge_j,x)^(x-1)!=Mod(1,x), return(0));\
      Selfridge_d=(x-1)/Selfridge_p;\
      if(Mod(Selfridge_j,x)^Selfridge_d!=Mod(1,x),\
        Selfridge_t=Selfridge_j;break();\
      );\
    );\
    if(Selfridge_t==0,return(-1));\
  ); return(1);\
}\
\
{ Selfridge(x)=Selfridge_table[1]=x;\
  if(!isprime(x),return(0));\
  Selfridge_step=1; Selfridge_ptr=1;\
  while(Selfridge_step<=Selfridge_ptr,\
    Selfridge_xx=Selfridge_check(Selfridge_table[Selfridge_step]);\
    if(Selfridge_xx==0 || Selfridge_xx==-1, return(-1));\
    Selfridge_step++;\
  ); return(1);\
}\
\
selfridge(x)=Selfridge(x);
!exit

:
Selfridge_table=vector(1000,x,0);

{ Selfridge_check(x)=if(abs(x)<500000,return(1));
  Selfridge_f=factor(x-1);Selfridge_n=matsize(Selfridge_f)[1];
  for(Selfridge_k=1,Selfridge_n,
    Selfridge_p=Selfridge_f[Selfridge_k,1];
    if(Selfridge_p>=500000,
      if(Selfridge_ptr>=999,return(-1));
      Selfridge_ptr++; Selfridge_table[Selfridge_ptr]=Selfridge_p;
    );
    Selfridge_t=0;for(Selfridge_j=2,1000,
      if(Mod(Selfridge_j,x)^(x-1)!=Mod(1,x), return(0));
      Selfridge_d=(x-1)/Selfridge_p;
      if(Mod(Selfridge_j,x)^Selfridge_d!=Mod(1,x),
        Selfridge_t=Selfridge_j;break();
      );
    );
    if(Selfridge_t==0,return(-1));
  ); return(1);
}

{ Selfridge(x)=Selfridge_table[1]=x;
  if(!isprime(x),return(0));
  Selfridge_step=1; Selfridge_ptr=1;
  while(Selfridge_step<=Selfridge_ptr,
    Selfridge_xx=Selfridge_check(Selfridge_table[Selfridge_step]);
    if(Selfridge_xx==0 || Selfridge_xx==-1, return(-1));
    Selfridge_step++;
  ); return(1);
}

selfridge(x)=Selfridge(x);