fork download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5.  
  6. function printPrimes($n) {
  7. $i = 2;
  8. echo $i . PHP_EOL;
  9. $count = 1;
  10. while(true) {
  11. ++$i;
  12. $isPrime = true;
  13. for($j=2;$j<=sqrt($i);++$j) {
  14. if ($i % $j == 0)
  15. $isPrime = false;
  16. }
  17.  
  18. if ($isPrime) {
  19. echo $i . PHP_EOL;
  20. $count++;
  21. }
  22.  
  23. if ($count == $n)
  24. break;
  25. }
  26.  
  27. }
  28.  
  29.  
  30. printPrimes(10);
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
2
3
5
7
11
13
17
19
23
29