day1/exercise/pytriads.py
changeset 64 333092b68926
child 94 8c92864c184b
equal deleted inserted replaced
63:f5eac04a00fe 64:333092b68926
       
     1 def is_perfect_square(n):
       
     2     i = 1
       
     3     while i * i < n:
       
     4         i += 1
       
     5     return i * i == n, i
       
     6 
       
     7 def gcd(a, b):
       
     8     if a % b == 0:
       
     9         return b
       
    10     else:
       
    11         return gcd(b, a%b)
       
    12 
       
    13 for a in range(3, 100):
       
    14     for b in range(a+1, 100):
       
    15         ips, c = is_perfect_square((a * a) + (b * b))
       
    16         if ips and gcd(a, b) == 1:
       
    17             print a, b, c
       
    18