problem_two.py 655 B

12345678910111213141516171819202122232425262728293031323334
  1. from typing import Optional
  2. numbers: dict[str, int] = {}
  3. char = [
  4. "a",
  5. "b",
  6. "c",
  7. "d",
  8. ]
  9. while char:
  10. try:
  11. num = int(input().strip())
  12. numbers[char.pop(0)] = num
  13. except EOFError:
  14. break
  15. def find_solutions(a: int, b: int, c: int, d: int) -> Optional[list[int]]:
  16. solutions = []
  17. def equation(x: int) -> None:
  18. nonlocal solutions
  19. eq = a * (x**3) + b * (x**2) + c * x + d
  20. if eq == 0:
  21. solutions.append(x)
  22. for x in range(1001):
  23. equation(x)
  24. return solutions[::-1] if solutions else None
  25. if solutions := find_solutions(**numbers):
  26. print(*solutions)