2
$\begingroup$

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?

$\endgroup$

closed as unclear what you're asking by Somos, Lee David Chung Lin, ancientmathematician, rtybase, Rebellos Nov 22 '18 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
    $\begingroup$ 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. $\endgroup$ – Arthur Jul 16 '18 at 9:35
  • 2
    $\begingroup$ Ever heard of the Sieve of Eratosthenes? en.wikipedia.org/wiki/Sieve_of_Eratosthenes $\endgroup$ – Theo Bendit Jul 16 '18 at 9:36
  • 1
    $\begingroup$ Show us the alien numbers. $\endgroup$ – Yves Daoust Jul 16 '18 at 9:50
  • 1
    $\begingroup$ 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 $\endgroup$ – Cato Jul 16 '18 at 10:42
  • 2
    $\begingroup$ 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? $\endgroup$ – Robert Soupe Jul 16 '18 at 14:14

Browse other questions tagged or ask your own question.