开发者

Finding prime numbers [duplicate]

开发者 https://www.devze.com 2023-03-27 01:41 出处:网络
This question already has answers here: 开发者_Python百科Closed 11 years ago. Possible Duplicate: Which is the fastest algorithm to find prime numbers?
This question already has answers here: 开发者_Python百科 Closed 11 years ago.

Possible Duplicate:

Which is the fastest algorithm to find prime numbers?

What is the fastest way to check if a number is prime( large numbers). I have tried the standard method i.e running a loop till root(n) or (n/2) and checking if anything divides it. Also i have tried the sieve method. Is there anything better to implement in c++?


http://en.wikipedia.org/wiki/Primality_test has all you need.


One tip is that you can ignore any even numbers (so add 2 at a time when either looking for factors or checking values).

0

精彩评论

暂无评论...
验证码 换一张
取 消