Python勾股数元组

360影视 动漫周边 2025-03-26 16:00 3

摘要:import mathdef find_primitive_pythagorean_triples(N, M):triples = max_m = int(math.isqrt(M)) + 1for m in range(2, max_m):for n in

import mathdef find_primitive_pythagorean_triples(N, M):triples = max_m = int(math.isqrt(M)) + 1for m in range(2, max_m):for n in range(1, m):if (m - n) % 2 == 1 and math.gcd(m, n) == 1:a = m**2 - n**2b = 2 * m * nc = m**2 + n**2if a > b:a, b = b, aif N

来源:烨华教育

相关推荐