Prime Number Formula

前端 未结 13 1652
情话喂你
情话喂你 2020-12-06 08:47

I am trying to write a prime number function in C# and I am wondering if the follow code will work. It \"appears\" to work with the first 50 numbers or so. I just want to ma

13条回答
  •  孤街浪徒
    2020-12-06 09:24

    You are apparently writing from a contrafactual dimension where 9 is a prime number, so I guess that our answers might not work for you. Two things though:

    1. Prime number generating functions are a non-trivial but exiting matter, the Wikipedia page is a good starter (http://en.wikipedia.org/wiki/Formula_for_primes)

    2. from (number%2!=0) it follows (number%4!=0). If you can't divide by 10, then you can't divide by 100 either.

提交回复
热议问题