The document explains Euclid's formula for generating Pythagorean triplets using two coprime integers m and n. It defines coprime numbers and provides the formulas for calculating the triplets (a, b, c) such that a^2 + b^2 = c^2. An algorithm is presented to input a positive integer n and find all coprime pairs m and n to generate the corresponding Pythagorean triplets.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views1 page
Pythagorian Triplets
The document explains Euclid's formula for generating Pythagorean triplets using two coprime integers m and n. It defines coprime numbers and provides the formulas for calculating the triplets (a, b, c) such that a^2 + b^2 = c^2. An algorithm is presented to input a positive integer n and find all coprime pairs m and n to generate the corresponding Pythagorean triplets.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
# Theory:
# Euclid’s formula for generating Pythagorean triplets beginning with
a pair of positive integers m and n, # where they are coprime. What is coprime? Two integers m and n are said to be coprime # (or relative prime, mutual prime) when the greatest common divisor between them is 1. # For example, 14 and 15 are coprime but 14 and 21 are not coprime as they both are divisible by 7. # The formulas for Pythagorean triples (a, b, c) so that a^2+b^2=c^2 : a=m^2-n^2 ; b=2mn ; c=m^2+n^2
# Algorithm: # 1. Input: a positive integer n # 2. Take an integer m in the range [1, (n-1)] # 3. Find GCD between m and n # 4. Test if GCD = 1, calculate a, b, c from the formulas.
# Pythagorian Triplets by Euclid's formula
n = int(input('Give a number : \n'))
def gcd(a, b): # a > b
while b != 0: a0 = a a = b b = a0 % a # a, b=b ,a % b return a
for m in range(1, n):
if gcd(n, m) == 1: # m,n -> Coprime x = n * n - m * m y = 2 * n * m z = n * n + m * m print(x, y, z)