added tips to lamer.bash help
[mirrors/Programs.git] / php / skripty / prvocisla.php
1 <?php
2
3 //FUNCTION IS_PRIME()
4
5 function is_prime ($num) {
6
7 if($num < 2) { return (0); }
8 if ( ($num > 2) && (($num % 2) == 0) ) { return (0); }
9 $i = 2;
10 while ($i < $num) {
11 if ( ($num % $i) == 0 ) { return (0); }
12 $i++;
13 }
14 return (1);
15 }
16
17 //CODE
18
19 //Prvocisla: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, \85
20 //echo(is_prime(1)."\n".(7%2)); //Debug
21
22 //Settings
23 $min = 1;
24 $max = 3000;
25
26 //Logic
27 $total_primes = 0;
28 while ($min <= $max) {
29 if(is_prime($min)) {
30 echo($min."\n"); //Show all primes
31 $total_primes++; //Count all primes
32 }
33 $min++;
34 }
35
36 //Output
37 echo("\nPrimes total: ".$total_primes."\n"); //Total number of primes
38
39 ?>
This page took 1.723268 seconds and 4 git commands to generate.