36 lines
595 B
Text
36 lines
595 B
Text
;;; find some semiprimes - numbers with two prime factors
|
|
|
|
PROGRAM semiPrimes
|
|
INCLUDE library
|
|
|
|
FUNC BYTE isSemiPrime
|
|
ARG WORD n
|
|
WORD f
|
|
WORD factorCount
|
|
BYTE result
|
|
BEGIN
|
|
f = 2
|
|
factorCount = 0
|
|
WHILE factorCount < 3 AND n > 1
|
|
WHILE n % f = 0
|
|
factorCount = factorCount + 1
|
|
n = n / f
|
|
f = f + 1
|
|
IF factorCOunt = 2
|
|
result = 1
|
|
ELSE
|
|
result = 0
|
|
RETURN result
|
|
END
|
|
|
|
WORD n
|
|
BEGIN
|
|
OUTPUT "Semiprimes under 100:#C "
|
|
FOR n = 1 TO 99
|
|
IF isSemiPrime( n )
|
|
OUTPUT " #W", n
|
|
OUTPUT "#CSemiprimes between 1670 and 1690:#C "
|
|
FOR n = 1670 TO 1690
|
|
IF isSemiPrime( n )
|
|
OUTPUT " #W", n
|
|
END
|