Posts: 1,845
Threads: 44
Joined: Aug 2002
Hrmm. So it's Sieve. I'd just translated the title from Dutch, so I didn't know the exact English title. Anyway, I'm going home now...
Posts: 1,845
Threads: 44
Joined: Aug 2002
Ok, here it is:
Code:
' ==============
' Prime Module
'By Zack & Neo Deus Ex Machina
'
'This Module is part of the KetOn library
'made by members of HAR-SoftWare
'
'This Module contains:
' 2 Prime Routines
'
'Test Function (1 routine)
DECLARE FUNCTION KT.PRIME.IsPrime% (NumberToCheck AS LONG)
'Sea Function (1 routine)
DECLARE SUB KT.PRIME.Erathetos (ArrayToFill() AS INTEGER, StartNumber AS LONG)
'$DYNAMIC
DEFINT A-Z
'###############
' Test Function
'###############
FUNCTION KT.PRIME.IsPrime (NumberToCheck AS LONG)
'IsPrime function, By Zack
FOR i& = 2 TO NumberToCheck \ 2 'Start the loop that will test to see if the number isn't prime
IF NumberToCheck / i& = NumberToCheck \ i& THEN 'If the number isn't prime
KT.PRIME.IsPrime = 0 'Return 0
EXIT FUNCTION 'Exit the function
END IF
NEXT i&
KT.PRIME.IsPrime = -1 'If the number is prime, return -1
END FUNCTION
'##############
' Sea Function
'##############
SUB KT.PRIME.Erathetos (ArrayToFill() AS INTEGER, StartNumber AS LONG)
'Erathetos function, By Neo Deus Ex Machina
endnumber& = UBOUND(ArrayToFill) + StartNumber 'calculate the last number to check
begNumber& = StartNumber \ 2
IF begNumber& < 2 THEN begNumber& = 2
FOR i& = 0 TO UBOUND(ArrayToFill) 'fill the array with &HFFFF
ArrayToFill(i&) = -1
NEXT i&
loopto& = endnumber& \ 2 'last loop number
FOR i& = 2 TO loopto&
begNumber& = StartNumber \ i&
IF begNumber& < 2 THEN begNumber& = 2
FOR inloop& = begNumber& TO endnumber& \ i&
multiplication& = inloop& * i& 'this is no prime
IF multiplication& >= StartNumber THEN ArrayToFill(multiplication& - StartNumber) = 0 'put in array that this is no prime
NEXT inloop&
NEXT i&
END SUB
Hope it helps!
Posts: 1,845
Threads: 44
Joined: Aug 2002
Btw, how's this?:
Quote:All primes:
up to 1,000,000: 16,6 seconds
up to 10,000,000: 780 seconds
:roll:
Posts: 1,845
Threads: 44
Joined: Aug 2002
I know, but if I run the program during the night, I might reach, or get over the 100,000,000 primes