Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The PRIME NUMBERS
#31
Well, actually I could do it faster:
-Limited size of tables so they fit in dgroup.
-Saves primes into a file so you can check them
-It displays one prime every 16000 so you can see it's working
-It calculates and saves 300,000 primes in 1 minute (compiled)
The highest prime it can calculate should be under 2^30, it makes around 5,000,000 primes. However,I have not patiented to see the end Big Grin, it can take hours and probably it ends by an error.

Code:
CLS
PRINT "PRIME CALCULATOR BY ANTONI GUAL agual@eic.ictnet.es"
'Version 2.
CONST pp = 1024& * 16 - 1

CONST stor = 3400 'enough to calculate the 10,000,000 first primes
DIM pr(stor + 2) AS INTEGER
DIM pr1(stor + 2) AS LONG
DIM pr2(stor + 2) AS LONG
DIM ind AS LONG

'pr saves primes found
'pr1 saves primes multiplied by factor pr2
'We save pr2 to stop scanning the array if pr2<pr, this indicates that
' pr> sqr(test&) without having to calculate the square root.
'
'pr() saves primes, pr1()=pr()*pr2()

'init the tables with 3 and test our first candidate, 5
pr(2) = 3
pr1(2) = 3
pr2(2) = 1
maxx& = 2
ind = 2
test& = 5

t! = TIMER
OPEN "primes.txt" FOR OUTPUT AS #1
PRINT #1, 2, 3,
DO
isprime% = -1
i% = 1
DO
   i% = i% + 1
   WHILE pr1(i%) < test&: pr1(i%) = pr1(i%) + pr(i%): pr2(i%) = pr2(i%) + 1: WEND
   IF pr1(i%) = test& THEN isprime% = 0: EXIT DO
LOOP UNTIL pr2(i%) <= pr(i%)
IF isprime% THEN
  ind = ind + 1
  IF (ind AND pp) = 0 THEN PRINT USING "####### th prime is: ##########. Time:###.# sec."; ind; test&; TIMER - t!
  PRINT #1, test&,
  IF (ind AND 7) = 0 THEN PRINT #1,
  IF ind <= stor THEN
  pr(ind) = test&
  pr1(ind) = test&
  pr2(ind) = 1
  END IF
END IF
test& = test& + 2
LOOP UNTIL (i% = stor) OR LEN(INKEY$)
ERASE pr, pr1, pr2
CLOSE
Antoni
Reply


Messages In This Thread
The PRIME NUMBERS - by Touf - 05-05-2003, 05:46 AM
The PRIME NUMBERS - by toonski84 - 05-05-2003, 06:03 AM
The PRIME NUMBERS - by Plasma - 05-05-2003, 06:09 AM
The PRIME NUMBERS - by Touf - 05-05-2003, 05:54 PM
The PRIME NUMBERS - by Touf - 05-07-2003, 08:23 AM
The PRIME NUMBERS - by Mango - 05-07-2003, 11:51 PM
The PRIME NUMBERS - by ak00ma - 05-08-2003, 01:25 AM
The PRIME NUMBERS - by RST - 05-08-2003, 01:34 AM
The PRIME NUMBERS - by DrV - 05-08-2003, 05:52 AM
The PRIME NUMBERS - by Agamemnus - 05-08-2003, 08:04 AM
The PRIME NUMBERS - by RST - 05-08-2003, 07:12 PM
The PRIME NUMBERS - by Touf - 05-08-2003, 10:22 PM
The PRIME NUMBERS - by Touf - 05-12-2003, 05:47 PM
The PRIME NUMBERS - by Mango - 05-12-2003, 07:53 PM
The PRIME NUMBERS - by Touf - 05-13-2003, 02:52 AM
The PRIME NUMBERS - by wizardlife - 05-13-2003, 03:11 AM
The PRIME NUMBERS - by Antoni Gual - 05-14-2003, 02:31 AM
The PRIME NUMBERS - by Touf - 05-29-2003, 05:46 AM
The PRIME NUMBERS - by Mango - 05-29-2003, 10:16 PM
The PRIME NUMBERS - by Touf - 06-02-2003, 04:31 PM
And the Russians beat the French. - by Agamemnus - 06-02-2003, 11:34 PM
The PRIME NUMBERS - by toonski84 - 06-02-2003, 11:39 PM
Re: And the Russians beat the French. - by Mango - 06-03-2003, 01:09 AM
The PRIME NUMBERS - by Antoni Gual - 06-03-2003, 01:44 AM
The PRIME NUMBERS - by Agamemnus - 06-03-2003, 01:49 AM
The PRIME NUMBERS - by whitetiger0990 - 06-03-2003, 01:56 AM
The PRIME NUMBERS - by Antoni Gual - 06-03-2003, 02:47 AM
The PRIME NUMBERS - by Agamemnus - 06-03-2003, 03:02 AM
Toonski - by Mango - 06-03-2003, 04:32 AM
The PRIME NUMBERS - by toonski84 - 06-03-2003, 04:42 AM
The PRIME NUMBERS - by Antoni Gual - 06-03-2003, 04:48 AM
Antonio...re not using squareroots... - by Mango - 06-03-2003, 05:21 AM
The PRIME NUMBERS - by Antoni Gual - 06-03-2003, 05:37 AM
The PRIME NUMBERS - by Touf - 06-03-2003, 02:07 PM
The PRIME NUMBERS - by Touf - 06-03-2003, 05:09 PM
WHAT! WheRE DID MY POST GO? - by Agamemnus - 06-03-2003, 09:15 PM
The PRIME NUMBERS - by Antoni Gual - 06-03-2003, 10:51 PM
The PRIME NUMBERS - by toonski84 - 06-03-2003, 11:04 PM
The PRIME NUMBERS - by Agamemnus - 06-03-2003, 11:10 PM
The PRIME NUMBERS - by toonski84 - 06-03-2003, 11:16 PM
The PRIME NUMBERS - by ak00ma - 06-04-2003, 12:04 AM
The PRIME NUMBERS - by Touf - 06-04-2003, 12:18 AM
The PRIME NUMBERS - by Antoni Gual - 06-04-2003, 01:01 AM
The PRIME NUMBERS - by Agamemnus - 06-04-2003, 01:43 AM
The PRIME NUMBERS - by whitetiger0990 - 06-04-2003, 01:52 AM
The PRIME NUMBERS - by Neo - 06-04-2003, 02:42 PM
The PRIME NUMBERS - by Mango - 06-04-2003, 07:48 PM
The PRIME NUMBERS - by Antoni Gual - 06-05-2003, 04:13 AM
The PRIME NUMBERS - by Agamemnus - 06-05-2003, 04:19 AM
The PRIME NUMBERS - by Neo - 06-05-2003, 12:12 PM
The PRIME NUMBERS - by Antoni Gual - 06-06-2003, 07:01 PM
The PRIME NUMBERS - by Joakim - 06-08-2003, 02:21 AM
The PRIME NUMBERS - by Agamemnus - 06-08-2003, 04:25 AM
The PRIME NUMBERS - by Antoni Gual - 06-08-2003, 06:20 PM
The PRIME NUMBERS - by whitetiger0990 - 06-09-2003, 04:34 AM
The PRIME NUMBERS - by Antoni Gual - 06-09-2003, 05:01 AM
The PRIME NUMBERS - by oracle - 06-09-2003, 05:12 AM
The PRIME NUMBERS - by Antoni Gual - 06-09-2003, 05:45 AM
The PRIME NUMBERS - by oracle - 06-09-2003, 05:46 AM
The PRIME NUMBERS - by Agamemnus - 06-09-2003, 06:59 AM
The PRIME NUMBERS - by whitetiger0990 - 06-09-2003, 07:24 AM
The PRIME NUMBERS - by Agamemnus - 06-09-2003, 07:30 AM
The PRIME NUMBERS - by whitetiger0990 - 06-09-2003, 07:36 AM
The PRIME NUMBERS - by Agamemnus - 06-09-2003, 11:07 PM
The PRIME NUMBERS - by Mango - 06-09-2003, 11:39 PM
The PRIME NUMBERS - by Antoni Gual - 06-09-2003, 11:53 PM
The PRIME NUMBERS - by whitetiger0990 - 06-10-2003, 12:55 AM
The PRIME NUMBERS - by oracle - 06-10-2003, 06:11 AM
The PRIME NUMBERS - by Antoni Gual - 06-11-2003, 03:01 AM
The PRIME NUMBERS - by Mango - 06-13-2003, 12:55 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)