-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.php
More file actions
36 lines (27 loc) · 623 Bytes
/
9.php
File metadata and controls
36 lines (27 loc) · 623 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
<?php
/**
* A Pythagorean triplet is a set of three natural numbers, a b c, for which,
*
* a^2 + b^2 = c^2
* For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
*
* There exists exactly one Pythagorean triplet for which a + b + c = 1000.
* Find the product abc.
*/
$start = microtime(true);
$a = 1;
$b = 2;
while (true) {
$c = 1000 - $a - $b;
if ($a * $a + $b * $b == $c * $c) {
break;
}
if ($a + 1 < $b) {
$a++;
} else {
$a = 1;
$b++;
}
}
echo ($a * $b * $c) . "\n";
printf("Resultado obtenido en %.4f segundos\n", microtime(true) - $start);