What's Here?
- Members: 149,626
- Replies: 506,753
- Topics: 79,851
- Snippets: 2,666
- Tutorials: 706
- Total Online: 1,985
- Members: 76
- Guests: 1,909
|
Implementation of the Sieve of Eratosthenes algorithm for finding prime numbers from 2 to N.
|
Submitted By: grimpirate
|
|
|
Rating:
|
|
Views: 186 |
Language: PHP
|
|
Last Modified: August 20, 2008 |
|
Instructions: The function takes as input the limit to which you wish to determine prime numbers (only tested up to 200,000 effectively as largest integer at 600,000 the computer hung). |
Snippet
function sieve_of_eratosthenes($limit){
if(! is_int($limit)) return false;
if($limit < 1) return false;
if($limit == 1) return $primes;
do{
$start = reset($numbers);
$primes[] = $start;
$inc = $start;
$start = bcmul($start, $start);
for($i = $start; bccomp($i, $end) <= 0; $i = bcadd($i, $inc))
}while(bccomp($start, $limit) < 0);
}
Copy & Paste
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|