#P7578. Divisible Sum Triples

    ID: 20772 Type: Default 1000ms 256MiB

Divisible Sum Triples

Divisible Sum Triples

Given three distinct positive integers \(x, y, z\) with \(x > y > z\), such that the sum of any two is divisible by the third, i.e.,

[ \begin{aligned} (x+y) \mod z &= 0,\ (x+z) \mod y &= 0,\ (y+z) \mod x &= 0, \end{aligned} ]

it can be proven that a family of solutions is \(x=3d,\; y=2d,\; z=d\) for any positive integer \(d\). Notice that \(x-y= d,\; x-z= 2d,\; y-z= d\).

This problem consists of three sub-problems. You will be provided with one difference value together with an option to indicate which difference is given:

  • Option 1: Given \(x-y\) (which equals \(d\)), find \(x, y, z\).
  • Option 2: Given \(x-z\) (which equals \(2d\)); note that the given value must be even.
  • Option 3: Given \(y-z\) (which equals \(d\)), find \(x, y, z\).

Input consists of two integers: the first integer indicates the option (1, 2, or 3) and the second integer is the provided difference value. For options 1 and 3, the parameter \(d\) is exactly the input difference; for option 2, if the given difference is even, then \(d\) equals half of that value. If the given difference does not satisfy the requirement (e.g. option 2 with an odd value), output No solution.

inputFormat

The first line contains two space-separated integers:

  • An integer opt (1, 2, or 3) indicating which difference is given, where:
    • 1 means the input is \(x-y\),
    • 2 means the input is \(x-z\),
    • 3 means the input is \(y-z\).
  • An integer diff representing the corresponding difference.

outputFormat

If a valid solution exists, output three space-separated integers \(x, y, z\) satisfying \(x > y > z\) and the divisibility condition. Otherwise, print No solution.

sample

1 2
6 4 2