|
|
|
|
|
|
|
|
|
Like this code?
Show the author your appreciation.
|
| |
This script uses Sieve of Erastothenes to find all the prime up to a number
| <?php
//Made by Chao Xu
//http://webdevlogs.com/
function esprime($limit){
$sqrtlimit = sqrt($limit);
$range = 0;
while($range<$limit){
$i .= '11';
$range+=2;
}
$n = 2;
while($n < $sqrtlimit){
if ($i[$n]){
$sqn = $n*$n;
$k = $sqn;
$i[$k]=0;
while($k<=$limit){
$k += $n;
$i[$k]=0;
}
}
++$n;
}
$n = 1;
while($n<$limit){
if($i[$n]) $primes[] = $n;
$n+=2;
}
if($limit>=2) $primes[0] = 2;
return $primes;
}
?> | |
It returns an array of all prime number below an the argument.
| <?php
esprime(6);
//return array(2,3,5);
?> | | |
|
| How to judge if an integer is odd or is even in Php3? Categories : Math., PHP, Algorithms | | | Library of math functions to expand the functionality of PHP3. Version 1.2.1 fixes a major problem with the gcd function.
Categories : Algorithms, PHP, Math. | | | Diffusion-Limited Aggregation visualization Categories : PHP, Graphics, Algorithms, Math. | | | Reverse a given number Categories : PHP, Beginner Guides, Algorithms, Math. | | | Show the steps for converting a number from a given base to base 10. Shows the steps involved in converting a number from a given base to base 10. Categories : PHP, Math., Algorithms | | | Output database records in multiple table columns.
multiple, table, columns, output, format, query output, html table, php Categories : General SQL, Algorithms, PHP, MySQL | | | Fast PI calculator. Can easily find the 1000th decimal place of pi in 5 seconds. Categories : PHP, BC math, Algorithms | | | Timer - a class that uses microtime() to provide easy calculation of elapsed times Categories : Algorithms, PHP, PHP Classes | | | minus - subtract arrays. Send two arrays and get an array with the operation A-B, elements on A that are not included on B. Categories : PHP, Arrays, Algorithms | | | Calculator for Baroque Violin strings Categories : Math., PHP, Strings | | | grab the result of any calculation you submit to the Google Calculator. Categories : PHP, Arrays, Web Services, Regexps, Math. | | | Greatest Common Denominator - A simple class that finds the greatest common denominator for two integers.
Categories : PHP, PHP Classes, Math. | | | quick sort for associative arrays Categories : Algorithms, Arrays, PHP | | | Arbitrary Precision Math using BCMATH routines Categories : PHP, Math., BC math | | | Function to convert Arabic numbers into Roman Numerals Categories : Algorithms, PHP, Date Time | |
| |
| |
|