If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.

{20,48,52}, {24,45,51}, {30,40,50}

For which value of p ≤ 1000, is the number of solutions maximised?


In [1]:
20**2 + 48**2, 52**2, 20+48+52


Out[1]:
(2704, 2704, 120)

a + b + c = p -> a^2 + b^2 + c^2 + 2ab + 2ac + 2bc = p^2

a^2 + b^2 = c^2

2*(c^2 + ab + ac + bc) = p^2 -> 2 | p


In [2]:
for i in range(60,500):
    solns = set()
    p = i*2
    for a in range(1,p):
        for b in range(1,p-a):
            c = p - a - b
            s = set([a,b,c])
            t = c*c - a*a - b*b
            if s not in solns and t == 0:
                solns.add(tuple(sorted(s)))
            elif t < 0:
                break
                
    if len(solns) > 0:
        print p, len(solns)


120 3
126 1
132 2
140 1
144 2
150 1
154 1
156 1
160 1
168 3
176 1
180 3
182 1
192 1
198 1
200 1
204 1
208 1
210 2
216 1
220 1
224 1
228 1
234 1
240 4
252 3
260 1
264 2
270 2
276 1
280 3
286 1
288 2
300 2
306 1
308 1
312 2
320 1
324 1
330 2
336 3
340 1
348 1
350 1
352 1
360 4
364 1
372 1
374 1
378 1
380 1
384 1
390 2
392 1
396 3
400 1
408 2
416 1
418 1
420 5
432 2
440 2
442 1
444 1
448 1
450 2
456 2
462 2
468 2
476 1
480 4
490 1
492 1
494 1
504 4
510 2
516 1
520 2
528 3
532 1
540 3
544 1
546 2
552 2
560 3
564 1
570 2
572 1
576 2
588 2
594 1
598 1
600 3
608 1
612 2
616 2
624 3
630 4
636 1
640 1
644 1
646 1
648 1
650 1
660 5
672 4
680 2
684 2
690 2
696 1
700 2
702 1
704 1
708 1
714 1
720 6
728 2
732 1
736 1
744 1
748 1
750 1
756 4
760 2
768 1
770 2
780 4
782 1
784 1
792 3
798 1
800 2
804 1
810 2
816 2
828 2
832 1
836 1
840 8
850 1
852 1
858 1
864 3
870 2
874 1
876 1
880 3
882 1
884 1
888 1
896 1
900 4
910 2
912 2
918 2
920 2
924 5
928 1
930 1
936 3
948 1
950 1
952 2
960 4
966 1
972 1
980 1
984 1
986 1
988 1
990 4
992 1
996 1

In [ ]: