+It turns out that 12 cm is the smallest length of wire that can be bent to form an integer sided right angle triangle in exactly one way, but there are many more examples.
+In contrast, some lengths of wire, like 20 cm, cannot be bent to form an integer sided right angle triangle, and other lengths allow more than one solution to be found; for example, using 120 cm it is possible to form exactly three different integer sided right angle triangles.
+120 cm: (30,40,50), (20,48,52), (24,45,51)
+Given that L is the length of the wire, for how many values of L ≤ 1,500,000 can exactly one integer sided right angle triangle be formed?
+Note: This problem has been changed recently, please check that you are using the right parameters.
+ return gcd($m,$n % $m);
+my $hypotenuse_lim = int($limit/2);
+my $major_side_limit = int($limit/2);
+for my $major_side (4 .. $major_side_limit)
+ if ($major_side % 100 == 0)
+ print "Maj=$major_side\n";
+ for my $minor_side (3 .. ($major_side - 1))
+ if (gcd( $major_side , $minor_side ) != 1)
+ my $hypot_sq = $major_side * $major_side + $minor_side * $minor_side;
+ my $hypot = sqrt($hypot_sq);
+ if ($hypot == int($hypot))
+ my $sum = $major_side + $minor_side + $hypot;
+ my $sum_product = $sum;
+ while ($sum_product < $limit)
+ # Only even numbers can be sums, so we can divide the index
+ my $idx = ($sum_product>>1);
+ if (vec($verdicts, $idx, 2) != 2)
+ vec($verdicts, $idx, 2)++;
+foreach my $sum_idx ((12>>1) .. ($limit>>1))
+ if (vec($verdicts, $sum_idx, 2) == 1)
+print "Count = $count\n";