fork download
  1. let rec gcd a b =
  2. if b = 0 then (a, 1, 0)
  3. else
  4. let (d, a_x, b_y) = gcd b (a mod b) in
  5. (d, b_y, a_x - (b_y * (a / b)))
  6.  
  7. let () =
  8. Scanf.scanf "%d %d %d" (fun a b c ->
  9. let (d, x, y) = gcd a b in
  10. if c mod d <> 0 then
  11. print_endline "Impossible"
  12. else
  13. let tru_x = x * c / d in
  14. let tru_y = y * c / d in
  15. let shift =
  16. if (abs tru_x) mod b <> 0 then
  17. (abs tru_x) / b + 1
  18. else
  19. (abs tru_x) / b
  20. in
  21. if tru_x > 0 then
  22. Printf.printf "%d %d\n" (tru_x - b * (shift - 1)) (tru_y + a * (shift - 1))
  23. else
  24. Printf.printf "%d %d\n" (tru_x + b * shift) (tru_y - a * shift)
  25. )
Success #stdin #stdout 0s 5284KB
stdin
1 2 3
stdout
1 1