I don't know anything about programming but I would like to figure out how to program this idea I had for calculating prime numbers. I know that this looks a little bit jumbled, but logically it should work.

My basic idea is that the square root of the first number that cannot be divided by 2 evenly that is not a prime number, is the next prime number. Therefore, if you were to work it out then you would come up with 9 who's square root is 3 which is the next prime number after two. Then you would find the first number after 9 that cannot be divided by 2 and 3, which would be 25 who's square root is 5 which is the next prime number after 3. And the program would hopefully be able to continue this progression infinitely without taking up all of the ram while outputting its findings to a simple text document. Any help would be appreciated.

Thank you

y1=2, y2=3, y3=5, and so on yn=the next prime number
the square root of x equals yn
x is the first non prime number that cannot be divided evenly by y1 or y2 or ...yn
loop adding yn as a divisor to each loop
output each y to text document append document for each yn
create new program for each loop
first loop will create program2
second loop will create program3
then the loops will alternate between program 2 and 3
the only difference between the programs are how many y's are being divided
the creation of the programs are in order to save ram so the y's are static and not held in memory
append programs 2 and 3 each time instead of creating new program

You would just use the modulus operator(%). Is this for homework? I got a number factoring program I wrote a while back for fun that will do what you want plus more. I can post it, but the rules say you gotta try first before you are helped.

Edited 6 Years Ago by clutchkiller: n/a

the first number after 9 that cannot be divided by 2 and 3, which would be 25

Perhaps I'm missing something but I don't really follow the logic of this statement at all. There are a bunch that cannot be divided by 2 or 3 or both.

If this is something you are interested in there are scores of webpages devoted to theory of primes, etc. Google can point the way.

Edited 6 Years Ago by jonsca: n/a

Perhaps I'm missing something but I don't really follow the logic of this statement at all. There are a bunch that cannot be divided by 2 or 3 or both.

If this is something you are interested in there are scores of webpages devoted to theory of primes, etc. Google can point the way.

from the looks of it I think he means the sqrt of each succeeding perfect square is the next prime number, I could be wrong.

Edited 6 Years Ago by EricDLundquist: n/a

from the looks of it I think he means the sqrt of each succeeding perfect square is the next prime number, I could be wrong.

Well, I don't exactly mean each succeding perfect sqrt so much as the sqrt of the only number excluding prime numbers that cannot be divided evenly by the previous series of prime numbers (2, 3, 5...) is the next prime number.

For example, 4, 6, & 8 can all be divided by 2 evenly. Therefore, the next number after 2 excluding primes that cannot be divided evenly by 2 is 9 and the sqrt of 9 is 3 or the next prime number. Then you just add the next prime number to the list of divisors to get the next prime and so on.

The only problem with this logic is that unless you already know that 9 is not prime then it won't work. I know it is a bit of circular logic, but it is an interesting pattern. I am sorry about not explaining myself very well. I was just in a hurry to get an answer. However, I did figure out that what I wanted to do is not possible because I would already have to have a list of prime numbers for this program to work that is why I marked it as solved.

Thanks for the help!

Sorry for wasting your time

Edited 6 Years Ago by angels21usa: n/a

This question has already been answered. Start a new discussion instead.