03-29-2005, 02:44 AM
How would you adjust this program to allow it to search though numbers higher than 32767. I just use an array to store if a number is prime or not, but once the array fills up that's just as far as it can go. Is there a way to use multiple array's or would I have to save if a number is prime or not to a file. Whatever you think is the best method of correcting it, enlighten me.
-----------------------------------------------------------------------------
CLS
INPUT "The highest number to go to"; maxnum%
time1! = TIMER
DIM array%(maxnum%)
FOR i% = 2 TO maxnum%
array%(i%) = 1
NEXT i%
FOR prime% = 2 TO SQR(maxnum%)
IF array%(prime%) = 1 THEN
FOR i% = 2 TO (maxnum% \ prime%)
array%(i% * prime%) = 0
NEXT i%
END IF
NEXT prime%
FOR prime% = 2 TO maxnum%
IF array%(prime%) = 1 THEN
PRINT prime%,
count = count + 1
END IF
NEXT prime%
time2! = TIMER
time! = time2! - time1!
PRINT
PRINT "This algorithm took a mere "; time!; " seconds."
PRINT "There are"; count; "prime numbers to"; maxnum%
INPUT "Would you like to go though the primes in sections"; choice$
IF choice$ = "yes" THEN GOTO yes:
end
yes:
FOR i% = 2 TO maxnum%
IF array%(i%) = 1 THEN
PRINT i%,
count1 = count1 + 1
END IF
IF count1 = 110 THEN
SLEEP
count1 = 0
END IF
NEXT i%
PRINT
PRINT "Finished"
SLEEP
END
-----------------------------------------------------------------------------
CLS
INPUT "The highest number to go to"; maxnum%
time1! = TIMER
DIM array%(maxnum%)
FOR i% = 2 TO maxnum%
array%(i%) = 1
NEXT i%
FOR prime% = 2 TO SQR(maxnum%)
IF array%(prime%) = 1 THEN
FOR i% = 2 TO (maxnum% \ prime%)
array%(i% * prime%) = 0
NEXT i%
END IF
NEXT prime%
FOR prime% = 2 TO maxnum%
IF array%(prime%) = 1 THEN
PRINT prime%,
count = count + 1
END IF
NEXT prime%
time2! = TIMER
time! = time2! - time1!
PRINT "This algorithm took a mere "; time!; " seconds."
PRINT "There are"; count; "prime numbers to"; maxnum%
INPUT "Would you like to go though the primes in sections"; choice$
IF choice$ = "yes" THEN GOTO yes:
end
yes:
FOR i% = 2 TO maxnum%
IF array%(i%) = 1 THEN
PRINT i%,
count1 = count1 + 1
END IF
IF count1 = 110 THEN
SLEEP
count1 = 0
END IF
NEXT i%
PRINT "Finished"
SLEEP
END