Algorithm to find prime numbers [closed]
up vote
2
down vote
favorite
For a loop up to positive integer $n$, I have deduced an algorithm that provides me with all the prime numbers plus some odd numbers, for example for $n=10000$ my algorithm gives me the count $1260$ while prime are $1229$.
In order to avoid the non-primes I run a loop till $1260$ and remove the numbers that are divisible by any of the number from the list of $1260$ numbers (provide from my algorithm) which provides me the exact number of primes ?
Is my approach correct or do I need to reconsider something?
prime-numbers
closed as unclear what you're asking by Somos, Lee David Chung Lin, ancientmathematician, rtybase, Rebellos Nov 22 at 17:20
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 2 more comments
up vote
2
down vote
favorite
For a loop up to positive integer $n$, I have deduced an algorithm that provides me with all the prime numbers plus some odd numbers, for example for $n=10000$ my algorithm gives me the count $1260$ while prime are $1229$.
In order to avoid the non-primes I run a loop till $1260$ and remove the numbers that are divisible by any of the number from the list of $1260$ numbers (provide from my algorithm) which provides me the exact number of primes ?
Is my approach correct or do I need to reconsider something?
prime-numbers
closed as unclear what you're asking by Somos, Lee David Chung Lin, ancientmathematician, rtybase, Rebellos Nov 22 at 17:20
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
7
How would we know whether the algorithm is correct or not if you haven't told us what it is. For instance, there is no way for us to know whether you missed a prime somewhere.
– Arthur
Jul 16 at 9:35
2
Ever heard of the Sieve of Eratosthenes? en.wikipedia.org/wiki/Sieve_of_Eratosthenes
– Theo Bendit
Jul 16 at 9:36
1
Show us the alien numbers.
– Yves Daoust
Jul 16 at 9:50
1
if your algorithm gave you non-prime numbers, then it has a glitch in it. The simplest algorithm I can think of is to count numbers from 2 to n-1 that are factors n, and if the count is zero, then n is prime. Are your 'failures' squares of odd primes, by any chance? On a computer it may be due to rounding errors, especially if you are using square root and floats
– Cato
Jul 16 at 10:42
2
At the very least tell us what some of these false primes you are getting are, these "pseudoprimes" if you will. Numbers like 91 and 4199?
– Robert Soupe
Jul 16 at 14:14
|
show 2 more comments
up vote
2
down vote
favorite
up vote
2
down vote
favorite
For a loop up to positive integer $n$, I have deduced an algorithm that provides me with all the prime numbers plus some odd numbers, for example for $n=10000$ my algorithm gives me the count $1260$ while prime are $1229$.
In order to avoid the non-primes I run a loop till $1260$ and remove the numbers that are divisible by any of the number from the list of $1260$ numbers (provide from my algorithm) which provides me the exact number of primes ?
Is my approach correct or do I need to reconsider something?
prime-numbers
For a loop up to positive integer $n$, I have deduced an algorithm that provides me with all the prime numbers plus some odd numbers, for example for $n=10000$ my algorithm gives me the count $1260$ while prime are $1229$.
In order to avoid the non-primes I run a loop till $1260$ and remove the numbers that are divisible by any of the number from the list of $1260$ numbers (provide from my algorithm) which provides me the exact number of primes ?
Is my approach correct or do I need to reconsider something?
prime-numbers
prime-numbers
edited Nov 21 at 12:21
amWhy
191k27223439
191k27223439
asked Jul 16 at 9:28
Gaurav
111
111
closed as unclear what you're asking by Somos, Lee David Chung Lin, ancientmathematician, rtybase, Rebellos Nov 22 at 17:20
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Somos, Lee David Chung Lin, ancientmathematician, rtybase, Rebellos Nov 22 at 17:20
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
7
How would we know whether the algorithm is correct or not if you haven't told us what it is. For instance, there is no way for us to know whether you missed a prime somewhere.
– Arthur
Jul 16 at 9:35
2
Ever heard of the Sieve of Eratosthenes? en.wikipedia.org/wiki/Sieve_of_Eratosthenes
– Theo Bendit
Jul 16 at 9:36
1
Show us the alien numbers.
– Yves Daoust
Jul 16 at 9:50
1
if your algorithm gave you non-prime numbers, then it has a glitch in it. The simplest algorithm I can think of is to count numbers from 2 to n-1 that are factors n, and if the count is zero, then n is prime. Are your 'failures' squares of odd primes, by any chance? On a computer it may be due to rounding errors, especially if you are using square root and floats
– Cato
Jul 16 at 10:42
2
At the very least tell us what some of these false primes you are getting are, these "pseudoprimes" if you will. Numbers like 91 and 4199?
– Robert Soupe
Jul 16 at 14:14
|
show 2 more comments
7
How would we know whether the algorithm is correct or not if you haven't told us what it is. For instance, there is no way for us to know whether you missed a prime somewhere.
– Arthur
Jul 16 at 9:35
2
Ever heard of the Sieve of Eratosthenes? en.wikipedia.org/wiki/Sieve_of_Eratosthenes
– Theo Bendit
Jul 16 at 9:36
1
Show us the alien numbers.
– Yves Daoust
Jul 16 at 9:50
1
if your algorithm gave you non-prime numbers, then it has a glitch in it. The simplest algorithm I can think of is to count numbers from 2 to n-1 that are factors n, and if the count is zero, then n is prime. Are your 'failures' squares of odd primes, by any chance? On a computer it may be due to rounding errors, especially if you are using square root and floats
– Cato
Jul 16 at 10:42
2
At the very least tell us what some of these false primes you are getting are, these "pseudoprimes" if you will. Numbers like 91 and 4199?
– Robert Soupe
Jul 16 at 14:14
7
7
How would we know whether the algorithm is correct or not if you haven't told us what it is. For instance, there is no way for us to know whether you missed a prime somewhere.
– Arthur
Jul 16 at 9:35
How would we know whether the algorithm is correct or not if you haven't told us what it is. For instance, there is no way for us to know whether you missed a prime somewhere.
– Arthur
Jul 16 at 9:35
2
2
Ever heard of the Sieve of Eratosthenes? en.wikipedia.org/wiki/Sieve_of_Eratosthenes
– Theo Bendit
Jul 16 at 9:36
Ever heard of the Sieve of Eratosthenes? en.wikipedia.org/wiki/Sieve_of_Eratosthenes
– Theo Bendit
Jul 16 at 9:36
1
1
Show us the alien numbers.
– Yves Daoust
Jul 16 at 9:50
Show us the alien numbers.
– Yves Daoust
Jul 16 at 9:50
1
1
if your algorithm gave you non-prime numbers, then it has a glitch in it. The simplest algorithm I can think of is to count numbers from 2 to n-1 that are factors n, and if the count is zero, then n is prime. Are your 'failures' squares of odd primes, by any chance? On a computer it may be due to rounding errors, especially if you are using square root and floats
– Cato
Jul 16 at 10:42
if your algorithm gave you non-prime numbers, then it has a glitch in it. The simplest algorithm I can think of is to count numbers from 2 to n-1 that are factors n, and if the count is zero, then n is prime. Are your 'failures' squares of odd primes, by any chance? On a computer it may be due to rounding errors, especially if you are using square root and floats
– Cato
Jul 16 at 10:42
2
2
At the very least tell us what some of these false primes you are getting are, these "pseudoprimes" if you will. Numbers like 91 and 4199?
– Robert Soupe
Jul 16 at 14:14
At the very least tell us what some of these false primes you are getting are, these "pseudoprimes" if you will. Numbers like 91 and 4199?
– Robert Soupe
Jul 16 at 14:14
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
7
How would we know whether the algorithm is correct or not if you haven't told us what it is. For instance, there is no way for us to know whether you missed a prime somewhere.
– Arthur
Jul 16 at 9:35
2
Ever heard of the Sieve of Eratosthenes? en.wikipedia.org/wiki/Sieve_of_Eratosthenes
– Theo Bendit
Jul 16 at 9:36
1
Show us the alien numbers.
– Yves Daoust
Jul 16 at 9:50
1
if your algorithm gave you non-prime numbers, then it has a glitch in it. The simplest algorithm I can think of is to count numbers from 2 to n-1 that are factors n, and if the count is zero, then n is prime. Are your 'failures' squares of odd primes, by any chance? On a computer it may be due to rounding errors, especially if you are using square root and floats
– Cato
Jul 16 at 10:42
2
At the very least tell us what some of these false primes you are getting are, these "pseudoprimes" if you will. Numbers like 91 and 4199?
– Robert Soupe
Jul 16 at 14:14