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)
