Home  >  Article  >  Backend Development  >  It crashed after only 10 million. JAVA can easily reach 100 million without crashing. It doesn't have any optimization algorithm. Python is also unsupportable.

It crashed after only 10 million. JAVA can easily reach 100 million without crashing. It doesn't have any optimization algorithm. Python is also unsupportable.

WBOY
WBOYOriginal
2016-07-25 09:09:33761browse
  1. #!/usr/local/php53/bin/php
  2. /**
  3. * @params array=rs_array
  4. */
  5. #define(MAX,1000);
  6. $MAX = 1000;
  7. $from = 2;
  8. $rs_array= array();
  9. echo $MAX."以内的素数...n";
  10. while($from<$MAX){
  11. $is_susu=true;
  12. foreach($rs_array as $vals){
  13. if ((sqrt($from)+1) % $vals == 0 ){
  14. $is_susu=false;break;
  15. }
  16. }
  17. if($is_susu) {
  18. echo $from." ";
  19. $rs_array[]=$from;
  20. }
  21. $from++;
  22. }
  23. ?>
复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn