# Author : Steven Miller # Course Number : 22C:016 SCA # Student ID : 4784653 import math, time def pythagorean_triples(M) : count = 0 # Number of triples found x = 1 # Loop through values of x from 1 to M-1 while (x < M) : xsquared = x * x y = x + 1 # Loop through the values of y from x+1 to M while (y < M + 1) : ysquared = y * y xy_squared = xsquared + ysquared # Compute the nearest integer to square root of zsquared z = int(math.sqrt(xy_squared)) # Found a pythagorean triple if zsquared = z*z if z * z == xy_squared : count = count + 1 print x, y, z y = y + 1 x = x + 1 return count # Enter the cutoff M C = int(raw_input("Enter a positive integer for M: ")) start = time.time() print "The number of triples found is" + str(pythagorean_triples(C)) end = time.time() print "Time was " + str(end-start)