求多元三次方程(丢番图方程)整数解的Python代码?

问题描述 投票:0回答:0

我的方程是一个多元三次方程,我想求它在给定区间x = range(-10,11)内的整数解。方程是

a3 + b3 + c3 + d3 + e3 - (a + b + c + d + e)3 = 0

下面的代码正确吗?

from itertools import product
def find_solutions():
    possible_values = range(-10, 11)
    variable_combinations = product(possible_values, repeat=5)
    solutions = []
    for combination in variable_combinations:
        if sum(combination) == 0 and sum(i**3 for i in combination) == 0:
            sorted_solution = tuple(sorted(combination))
            if sorted_solution not in solutions:
                solutions.append(sorted_solution)
    return solutions
python equation-solving diophantine
© www.soinside.com 2019 - 2024. All rights reserved.