' FACTORING PROGRAM
'
' This program displays all the prime numbers
' under 1000, and then it lists the factors
' of all numbers between 6 and 1000.
'
' Written by Zsolt Nagy-Perge in December 2000.
'
'
DEFINT A-Z
CONST MAXVALUE = 1000 ' numbers to factor
DIM P(1 TO MAXVALUE) ' products
CLS
PRINT "PRIME NUMBERS:"
PRINT
' Factor all numbers.
FOR I = 6 TO MAXVALUE
FOR L = 2 TO MAXVALUE
IF I * L > MAXVALUE THEN EXIT FOR
P(I * L) = P(I * L) + 1
NEXT L
NEXT I
' Print prime numbers.
FOR I = 1 TO MAXVALUE
IF P(I) < 2 THEN PRINT LTRIM$(STR$(I)); CHR$(9);
NEXT I
PRINT
PRINT "PRESS ENTER TO CONTINUE...";
LINE INPUT L$
' Print factors for all numbers.
FOR A = 1 TO MAXVALUE
N = A
PRINT LTRIM$(STR$(N)) + CHR$(9); "=";
FOR I = 2 TO N
' Divide N by its prime factors.
IF P(I) < 2 THEN
DO WHILE (N MOD I) = 0
PRINT I;
IF I < N THEN PRINT "x";
N = N / I
LOOP
END IF
NEXT I
PRINT
NEXT A