Run ID:85271
提交时间:2024-07-16 20:46:33
def find_chicken_solutions(N): solutions = [] for m in range(0, N // 3 + 1): # x = 3m x = 3 * m for k in range(0, (N - x) // 3 + 1): # z = 3k z = 3 * k y = 2 * k - 5 * m if y >= 0 and x + y + z == N: solutions.append((x, y, z)) return solutions def print_chicken_solutions(solutions): if solutions: for i, (x, y, z) in enumerate(solutions, 1): print(f"{i}: {x},{y},{z}") else: print("None") # 输入N N = int(input().strip()) # 找到所有可能的解 solutions = find_chicken_solutions(N) # 打印解 print_chicken_solutions(solutions)