Let's try it in the spanish way:

The best way to calculate a square root is not calculating it at all..

No divisions or MOD either..

It calculates 16384 primes in 3 seconds in my P4 1,4... to display them it takes a little longer.

Antonio...note that in my May 7 post, I used a similar method to avoid the sqrt issue ...using 2 different methods for the big primes and for the small primes:

1st

LOOP WHILE smallprimes(a) * smallprimes(a) < next1

2nd

LOOP WHILE (nextbig& \ smallprimes(a)) > smallprimes(a)

I used the 2nd method because the numbers got too big when the direct square was used.

However, when I tweaked the code a bit in my May 29 post...I used SQR...outside the loop. which turned out to be faster. Also, by using a separate array to hold the small primes you don't have the problem of overflow errors...and if you hold the small primes as integers (for the ones smaller than 32000) and use these to test the long integer primes, both save memory and gain on speed.

OT...I looked at your file handling routines last week...thanks.

To the people just now posting their prime-finding methods...just to make sure we are all on the same page, as the recent methods haven't been printing all the primes (even though they were calculated), if you want to see if your method is a contender, make it print all primes using the semicolon...eg:

PRINT myprime&;

and compare the output to the output of the following code by Me and Argamemnus:

In the iteration before this, the code just printed one prime every second...which is a convienient way to see the highest prime that will be printed in, say, 10 seconds. However, this may be confusing to those just joining the fray...

I'm sure we'd all love to see a faster method than this...

DIM prime(1 TO 5000) AS INTEGER, cur.prime.amount AS INTEGER

cur.prime.amount% = 1

prime%(1) = 2

i% = 3

1 j% = 0

sqrt.num% = SQR(i%)

2 j% = j% + 1

temp% = prime%(j%)

IF i% MOD temp% = 0 THEN GOTO 4

IF temp% >= sqrt.num% THEN GOTO 3

GOTO 2

3 cur.prime.amount% = cur.prime.amount% + 1

prime%(cur.prime.amount%) = i%: PRINT i%;

4 IF i% = 32767 THEN GOTO 5

i% = i% + 2

GOTO 1

5 i2& = prime(cur.prime.amount%)

i2& = i2& + 2

biggest.prime& = i2&

6 j% = 1

sqrt.num% = SQR(i2&)

7 temp% = prime(j%)

IF i2& MOD temp% = 0 THEN GOTO 9

IF temp% >= sqrt.num% THEN GOTO 8

j% = j% + 1

GOTO 7

8 PRINT i2&;

9 i2& = i2& + 2

GOTO 6

Argamemnus...is this post OK that I give shared credit for the code? If not, I'll erase the whole thing...

Cheers, and thanks for the tips, people.