Run ID:85299
提交时间:2024-07-16 21:25:28
def find_chicken_solutions(N): solutions = [] for x in range(N // 5 + 1): # 公鸡最多为N/5 for y in range((N - x) // 3 + 1): # 母鸡的数量 z = N - x - y # 计算小鸡的数量 if z % 3 == 0 and 5 * x + 3 * y + z // 3 == N: solutions.append((x, y, z)) break # 找到一种解后,跳出当前循环继续寻找其他解 return solutions def print_solutions(solutions): if not solutions: print('None') else: for index, (x, y, z) in enumerate(solutions, start=1): print(f'{index}: {x},{y},{z}') N = int(input()) solutions = find_chicken_solutions(N) print_solutions(solutions)