Special pythagorean triplet: Difference between revisions

→‎{{header|ALGOL 68}}: Optimisation - m and n must have different parity - i.e. one is even and one is odd
(→‎{{header|PL/M}}: Minor tweak)
(→‎{{header|ALGOL 68}}: Optimisation - m and n must have different parity - i.e. one is even and one is odd)
Line 11:
# a + b + c = 1000, a2 + b2 = c2, a < b < c #
INT sqrt 1000 = ENTIER sqrt( 1000 );
FOR n TO sqrt 1000 DO # m and must have different parity, i.e. one even, one odd #
FOR m FROM n + 1 BY 2 TO sqrt 1000 DO
# a = m^2 - n^2, b = 2mn, c = m^2 + n^2 ( Euclid's formula ), so #
# a + b + c = m^2 - n^2 + 2mn + m^2 + n^2 = 2( m^2 + mn ) = 2m( m + n ) #
3,043

edits