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) |
ZnJvbSBtYXRoIGltcG9ydCBmbG9vciwgc3FydApmcm9tIGZyYWN0aW9ucyBpbXBvcnQgZ2NkCgpkZWYgY291bnRfcHl0aGFnb3JlYW5fdHJpcGxlcyhNQVhQKToKICAgIGNvdW50ID0gMAogICAgZm9yIG0gaW4geHJhbmdlKDEsIGludChmbG9vcihzcXJ0KE1BWFAvMikpKSArIDEpOgogICAgICAgIGZvciBuIGluIHhyYW5nZSAoMSwgbSk6CiAgICAgICAgICAgIGlmIGdjZChtLCBuKSAhPSAxIG9yIGdjZChnY2QobSptIC0gbipuLCAyKm0qbiksIG0qbSArIG4qbikgIT0gMTogY29udGludWUKICAgICAgICAgICAgY291bnQgKz0gaW50KGZsb29yKE1BWFAvKDIqbSoobSArIG4pKSkpCiAgICByZXR1cm4gY291bnQKCnByaW50IGNvdW50X3B5dGhhZ29yZWFuX3RyaXBsZXMoMTAwMDAwMCkK
-
upload with new input
-
result: Success time: 0.93s memory: 12744 kB returned value: 0
808950


