Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. <?php
  2.  
  3. set_time_limit(60);
  4.  
  5. $output = 0;
  6.  
  7. function generatePrimeArraySum($n) {
  8.     $result = array();
  9.     $limit = sqrt($n);
  10.     for($i = 2; $i < $n; $i++) {
  11.         $result[$i] = true;
  12.     }
  13.     for($i = 2; $i < $limit; $i++) {
  14.         if($result[$i] == true) {
  15.             for($j = ($i*$i); $j < $n; $j = ($j + $i)) {
  16.                 $result[$j] = false;
  17.             }
  18.         }
  19.     }
  20.     $return = array();
  21.     for($i = 2; $i < $n; $i++) {
  22.         if($result[$i] == true) {
  23.             array_push($return, $i);
  24.         }
  25.     }
  26.     return $return;
  27. }
  28.  
  29. $primearray = generatePrimeArraySum(2000000);
  30.  
  31. foreach($primearray as $value) {
  32.     $output = $output + $value;
  33. }
  34.  
  35. echo $output;
  36.  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement