Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board What is the 10001st prime number? Download Source Code
Author Details Code Information
perito

Pinned 7 Codes
Posted 0 Coding Articles

Send A Message
View Coders Profile
Language PHP (Hypertext Preprocessor)
Expires Never
Length 471 Characters (22 Lines)
Password no password
  1. $prime = array();
  2. $max = 200000;
  3.  
  4. function prime($input) {
  5. global $prime;
  6. return $prime[$input];
  7. }
  8.  
  9. function getPrimeByOrder($order) {
  10. global $prime;
  11. for($a = 0, $walk = 1; $a < $order ; $a += $prime[$walk], $walk++);
  12. return $walk - 1;
  13. }
  14.  
  15. for ($a = 2 ; $a <= $max ; $prime[$a] = 1, $a++);
  16.  
  17. for ($a = 2 ; $a <= sqrt($max); $a++) {
  18. if ($prime[$a] == 0) continue;
  19. for ($b = ($a+$a) ; $b <= $max ; $prime[$b] = 0, $b+=$a);
  20. }
  21.  
  22. echo getPrimeByOrder(10001);
code pin board Back To Code Pin Board Post New Code
Please login to post comments.
Page 1 of 1
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved