|
|
 |
 |
 |
|
|
| Author Details |
Code Information |
|
|
|
Language
|
PHP (Hypertext Preprocessor)
|
|
Expires
|
Never
|
|
Length
|
470 Characters (31 Lines)
|
|
Password
|
no password
|
|
|
<?php function find_nth_prime($x = 6) { // Find the $xth prime. $i = 3; $a = $b = 1; while ($i <= $x) { if ($b == 1) { $r = 6 * $a - 1; $b = 0; } else { $r = 6 * $a + 1; $b = 1; $a = $a + 1; } $c = pow($r, .5); $d = 1; $e = 3; while ($e <= $c) { if ($r % $e == 0) { $d = 0; } $e = $e + 2; } if ($d == 1) { $i = $i + 1; } } return $r; } echo find_nth_prime(10001); // 6.683 seconds ?> |
|
| Please login to post comments. |
|
|
|
|
| |
 |
 |
| |
::
::
::
::
|
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved
|
|
|
|
|