We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #39: Integer right triangles
Project Euler #39: Integer right triangles
Sort by
recency
|
18 Discussions
|
Please Login in order to post a comment
python 100%
JAva code
Here is my C# 100 points Soltuion
100/- points python 3
Python 3 Code Happy hacking
import math
def gcd(a, b): while b != 0: a, b = b, a % b return a
primiter = [0] * (5000 * 1000 + 1) for m in range(1, 2001): for n in range(1, m): if (m + n) % 2 and gcd(m, n) == 1: p = 2 * m * m + 2 * m * n if p > 5000000: continue primiter[p] += 1 i = 2 while i * p <= 5000000: primiter[i * p] += 1 i += 1
ans = [0] * (5000 * 1000 + 1) ans[12] = 12 for i in range(13, 5000 * 1000 + 1): if primiter[i] > primiter[ans[i - 1]]: ans[i] = i else: ans[i] = ans[i - 1]
t = int(input()) while t > 0: n = int(input()) print(ans[n]) t -= 1