Sign in to follow this  
Followers 0
BALA

Sieve of Eratosthenes

3 posts in this topic

#1 ·  Posted (edited)

I'm trying to create a function that I can use calculate all possible prime numbers. I decided to use Sieve of Eratosthenes as a model to base a function on.

I have something like this to calculate all possible multiples of a number:

n is a counting number not equal to 1

Multiples of n (starting with n squared):   n^2,   n^2 + n,   n^2 + 2n,   etc ...

Now, I need a way to have it "cross out" or ignore those multiples, then find the next number that isn't "crossed out." Also, I need to develop an array that will store the numbers that aren't "crossed out" (though this is just a simple array I could probably do by myself).

http://mathforum.org/dr.math/faq/faq.prime.num.html

Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites



I'm trying to create a function that I can use calculate all possible prime numbers.

That method doesnt treally do that since you have to define a stopping point.

Pulled this from an old basic program i wrote (pseudo-converted to auto it)

$n=3
$c=0
$a=0
While 1
    do 
        $a=$a+1
        $b=$n/$a
        if round($B)=$b then $c=$c+1
        if $c=2 then $a=$n
    until $a>($n/2)
    if $c=1 then FileWriteLine(@ScriptDir&"\test.txt",$n)
    $a=0
    $c=0
    $n=$n+2
Wend

seemed to still work ok.

but if you really still want to use the method your decribing well thats somthing else... can maybe think about that if you still want it

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yeah I meant to have a stopping point since there are an infinite number of prime numbers. :)

yeah that's what I need, thanks

Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0