fork download
  1. from math import floor, sqrt
  2. from fractions import gcd
  3.  
  4. def count_pythagorean_triples(MAXP):
  5. count = 0
  6. for m in xrange(1, int(floor(sqrt(MAXP/2))) + 1):
  7. for n in xrange (1, m):
  8. if gcd(m, n) != 1 or gcd(gcd(m*m - n*n, 2*m*n), m*m + n*n) != 1: continue
  9. count += int(floor(MAXP/(2*m*(m + n))))
  10. return count
  11.  
  12. print count_pythagorean_triples(1000000)
  13.  
Success #stdin #stdout 0.93s 12744KB
stdin
Standard input is empty
stdout
808950