Link Details

Link 368867 thumbnail
User 254199 avatar

By KlausG
Published: Feb 22 2010 / 22:56

n PHP is really no ideal way to test large integers and determine whether they are prime numbers or not. The most popular algorithm for finding prime numbers is a memory and resource hog. It is called The Sieve of Eratosthenes. Besides the Sieve I also implemented a prime number test by initializing an array of prime numbers from a file that contains the first 100,000 prime numbers. This is of course much faster, but would require files that contain all prime numbers up to a specific large number. The files of course could be partitioned, which would also increase performance.
  • 9
  • 0
  • 2760
  • 0


Add your comment
User 368023 avatar

yakkoh replied ago:

0 votes Vote down Vote up Reply

Faster for evenNumber is $number & 1
where & is the bit and.

also available for IsInteger: is_numeric and is_int.

Add your comment

Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (9)

Voters Against This Link (0)

    Reactive Programming with Akka
    Written by: Ryan Knight
    Featured Refcardz: Top Refcardz:
    1. Design Patterns
    2. OO JS
    3. Cont. Delivery
    4. Java Performance
    5. HTML5 Mobile
    1. Java Performance
    2. Node.js
    3. Debugging JavaScript
    4. Java
    5. Java Concurrency