00900 .PR POINT .PR
01000 .BEGIN #PRINT FIRST THOUSAND PRIME NUMBERS# 
01010   .INT THOUSAND = 320;
01020   .INT THIRTY = 30; #ACCORDING TO NUMBER THEORY, THE 30TH PRIME > SQRT(THE 1000TH PRIME)# 
01030   .LOC [1:THOUSAND] .INT P; # TABLE TO CONTAIN PRIMES # 
01040   .BEGIN # FILL TABLE P; P[K] WILL BE THE K'TH PRIME #
01050     P[1] := 2; # THE ONLY EVEN PRIME #
01060     .LOC .INT J := 1; # ODD NUMBER, TO BE INCREMENTED AND TESTED FOR PRIMENESS #
01070     .LOC .INT ORD := 1; 
01080       #.INVARIANT P[ORD]**2 > J # 
01090     .LOC .INT SQUARE := 4;
01100       #.INVARIANT SQUARE = P[ORD]**2 #
01110     .LOC [1:THIRTY] .INT MULT;
01120       #.INVARIANT MULT[N] IS A MULTIPLE OF P[N] FOR 1<=N<ORD #
01130     .FOR K .FROM 2 .TO THOUSAND 
01140     .DO .LOC .BOOL JPRIME;
01150       .WHILE
01160         J:=J+2; .WHILE SQUARE<=J .DO MULT[ORD]:=SQUARE; ORD+:=1; SQUARE:=P[ORD]**2 .OD; 
01170           #.ASSERT MULT[ORD] <= J # 
01180         JPRIME := .TRUE;
01190         .FOR N .FROM 2 .TO ORD-1 .WHILE JPRIME
01200         .DO # MAKE JPRIME=(P[N] IS NOT A FACTOR OF J) # 
01210           .REF .INT MULTN = MULT[N];
01220           .WHILE MULTN<J
01230           .DO MULTN+:=P[N] .OD; 
01240             #.ASSERT J <= MULT[N] < J+P[N] #
01250           JPRIME := J/=MULTN
01270         .OD;
01280         .NOT JPRIME 
01290       .DO .SKIP .OD;
01300       P[K] := J 
01310     .OD 
01320   .END; 
01330   .BEGIN # PRINT TABLE P ON 5 PAGES, EACH CONTAINING 4 COLUMNS WITH 50 CONSECUTIVE PRIMES # 
01340     PRINT(("TABLE OF FIRST ", THOUSAND, " PRIMES", NEWLINE)); 
01350     .INT COLUMNS = 4, LINES = 50; 
01360     .FOR PAGE 
01370     .WHILE .INT K = (PAGE-1)*COLUMNS*LINES+1; K<=THOUSAND 
01380     .DO # PRINT 1 PAGE #
01390       PRINT (("PAGE ", PAGE, NEWLINE)); 
01400       .FOR L .FROM K .TO K+LINES-1 .WHILE L<=THOUSAND 
01410       .DO # PRINT 1 LINE #
01420         .FOR M .FROM L .BY LINES .TO L+LINES*(COLUMNS-1) .WHILE M<=THOUSAND 
01430         .DO PRINT(P[M]) .OD;
01440         PRINT(NEWLINE)
01450       .OD;
01460       PRINT(NEWPAGE)
01470     .OD 
01480   .END
01490 .END
