4GHx qr>F >.d~!( **** PRIME NUMBERS ****
* by Graham Coward ------ Mbug # 531
3 This program can calculate all prime numbers
B (a prime number is evenly divisible only by itself and one)
& up to a maximum of six figures.
= While it is possible to do this with a simpler program
B my aim was to eliminate unneccessary calculations and thus
reduce running time.
? The program initialises by calculating the prime numbers
E which are less than the square root of 1,000,000 plus the next
: highest prime (1009). These are stored in array A0.
B You are then asked to enter the lower and upper limits that
C you want printed and whether output is to printer or screen.
H The program then tests all odd numbers (2 is the only even prime)
J between the specified limits by dividing them by the numbers stored
F in array A0. If any of these calculations comes out evenly, the
H number is not prime and the program jumps to the next odd number.
> *******************************************************
4 MR PRESIDENT.---- AN IDEA FOR A COMPETITION.
= I challenge anyone to write a BASIC program that will
* perform the same functions, FASTER.
d; ::A0(168):C=1:A0(1)=3:A1=1:87::" PRIME NUMBERS ":
n 256:"This program will print a list of prime numbers up to a maximum":"of six figures. The upper and lower limits may be chosen at"
x[ "will and the output may be directed to either printer or screen.":985:"PLEASE WAIT";
A1=A1+2:A1>1009180
D=1C:(A1/A0(D))=0*D 130
A0(D)*A0(D)>A1*D 170
D
C=C+1:A0(C)=A1:130
7 :"Lower Limit?"A3:"Upper Limit?"A2:A2>999999180
+ "Output to Printer or Screen? (P or S)"
S1$=$:S1$=""200
@ S1$="P"S1$="p""Press when printer ready!"Z1$:#1
:"PRIME NUMBERS"
A3<3:[F8.0A3];:A3=A3+1:230
(A3/2)=0:A3=A3+1
A3>A2280
6 I=1168:A0(I)*A0(I)>A3[F8.0A3];:A3=A3+2:*I 250
% (A3/A0(I))=0A3=A3+2:*I 250I
9 \"FINISHED":#0:"PRESS FOR MORE OR TO QUIT"
". S1$=$:S1$=""290S1$="q"S1$="Q":180
plist2 7a:>2(ÓMLEMp#qMͪw#Ќ߿$`߿(