A couple of quick mathematical tasks for this week's challenges.
Task 1: Pythagoras Multiplied
Task Description
You are given a positive integer n . Find the number of all positive integer triplets ( a,b,c ) so that a 2 + b 2 = c 2 and a , b , and c are integers <= n .
Example 1: n=20 --> 12
(3,4,5),(4,3,5),(5,12,13),(6,8,10),(8,6,10),(8,15,17),(9,12,15),(12,5,13),(12,9,15),(12,16,20),(15,8,17),(16,12,20)
Example 2: n=7 --> 2
Example 3: n=1 --> 0
Example 4: n=15 --> 8
Example 5: n=30 --> 22
Task Discussion
We notice from Example 1 that order matters: (3,4,5) is counted as distinct from (4,3,5).
We know from the geometry of right triangles that there are no integer solutions where a = b (an equilateral right triangle has hypotenuse sqrt(2)*a ), so all valid triples will have a ≠ b ≠ c .
I'm going to start by using brute force, and then thinking about optimizing. For every c from 1 to n , there is a target hypotenuse c 2 .…