Prime number calculation fun

前端 未结 18 1812
深忆病人
深忆病人 2020-12-05 15:32

We\'re having a bit of fun here at work. It all started with one of the guys setting up a Hackintosh and we were wondering whether it was faster than a Windows Box of (nearl

18条回答
  •  时光说笑
    2020-12-05 15:57

    Keeping in mind that there are better ways to look for primes...

    I think that you can take this loop:

    for (int i = 2; i < top; i++)

    and make it so that your counter variable i goes from 3 and only tries to do the mod on odd numbers, since all primes other than 2 are never divisible by any even numbers.

提交回复
热议问题