-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.php
More file actions
44 lines (39 loc) · 970 Bytes
/
test.php
File metadata and controls
44 lines (39 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$limit = 5;
$sieve = array_fill(0, $limit, false);
$sieve[0] = $sieve[1] = false;
$sieve[2] = $sieve[3] = true;
$limitSqrt = (int) sqrt($limit);
for($x = 1; $x <= $limitSqrt; $x++) {
for($y = 1; $y <= $limitSqrt; $y++) {
$n = (4 * $x * $x) + ($y * $y);
if($n<=$limit && ($n % 12 == 1 || $n % 12 == 5)) {
$sieve[$n] = ! $sieve[$n];
}
$n = (3 * $x * $x) + ($y * $y);
if($n<=$limit && ($n % 12 == 7) ) {
$sieve[$n] = ! $sieve[$n];
}
$n = (3 * $x * $x) - ($y * $y);
if($x > $y && $n<=$limit && ($n % 12 == 11) ) {
$sieve[$n] = ! $sieve[$n];
}
}
}
for($i=5; $i <= $limitSqrt; $i++) {
if($sieve[$i]) {
$x = $i * $i;
for($j=$x; $j<=$limit; $j+=$x) {
$sieve[$j] = false;
}
}
}
$sol = [];
$i=0;
$flag = true;
for($i=0;$i<=$limit;$i++) {
if($sieve[$i]) {
$sol[$i] = $i;
}
}
echo sizeof($sol);