100 ' ======================= 110 ' | Proving Primality | 120 ' ======================= 130 ' 140 ' program: aks_c4.ub 150 ' Aldo D., February 1, 2003 160 ' 170 ' This program is based on AKS Conjecture 4 and on 180 ' Michael Scott's MIRACL program. In this program 190 ' parameter r is prime number or a power of prime. 200 ' 210 ' Integer n having more than 4288 bits may cause 220 ' an overflow. 230 ' 240 emaword -268 250 ' 260 input "Input n:";N 270 ' 280 I=1:R=2:K=N@R 290 while (K^2@R=1) 300 inc R 310 K=N@R 320 wend 330 ' 340 if K=0 then print "N is divisible by";R:end 350 print "r =";R;":";"k =";K 360 ' 370 S=0:T=1 380 dim ema(S;R+1,0),ema(T;R+1,0),A(2) 390 ' 400 A(0)=-1:A(1)=1:' A = x-1 410 ema(T;0,0)=-1:ema(T;1,0)=1 420 ' 430 ' Mod exp: (x-1)^n (mod x^r-1, n) 440 ' ------------------------------- 450 I=len(N)-2 460 while (I>=0) 470 gosub *S_x_S:' (S*S)@(x^r-1)@n 480 if bit(I,N)=1 then gosub *S_x_A:' (S*A)@(x^r-1)@n 490 dec I 500 wend 510 ' 520 ' Test result 530 ' ----------- 540 block ema(S;*,0)=0 550 ema(S;K,0)=1 560 ema(S;0,0)=N-1 570 ' 580 I=0 590 while and{I