language: Python (python 2.7.3)
date: 209 days 21 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
from math import floor, sqrt
from fractions import gcd
 
def count_pythagorean_triples(MAXP):
    count = 0
    for m in xrange(1, int(floor(sqrt(MAXP/2))) + 1):
        for n in xrange (1, m):
            if gcd(m, n) != 1 or gcd(gcd(m*m - n*n, 2*m*n), m*m + n*n) != 1: continue
            count += int(floor(MAXP/(2*m*(m + n))))
    return count
 
print count_pythagorean_triples(1000000)