Official

B - LCM Editorial by evima


By symmetry, we assume \(A_1 \le A_2\).

Since \(\operatorname{lcm}(X_1,X_2) \geq X_2\), if \(A_3 < A_2\), the answer is No. Also, since \(\operatorname{lcm}(X_1,X_2) \le X_1 \times X_2 < 10^{A_1+A_2}\), if \(A_3 > A_1+A_2\), the answer is also No.

In all other cases, the answer is always Yes. Specifically, we can construct as follows:

  • When \(A_1+A_2=A_3\): \((X_1,X_2)=(8\times 10^{A_1-1}+1,8\times 10^{A_2-1})\)
  • When \(A_1+A_2 < A_3\): \((X_1,X_2)=(10^{A_1-1},10^{A_2}-10^{A_1+A_2-A_3-1})\)

Sample Implementation (Python3)

for _ in range(int(input())):
    a1, a2, a3 = map(int, input().split())
    swap = a1 > a2
    if swap:
        a1, a2 = a2, a1

    def o(x1, x2):
        print("Yes")
        if swap:
            x1, x2 = x2, x1
        print(x1, x2)

    if a3 > a1 + a2 or a3 < a2:
        print("No")
    elif a3 == a1 + a2:
        o(8 * 10 ** (a1 - 1) + 1, 8 * 10 ** (a2 - 1))
    else:
        o(10 ** (a1 - 1), 10**a2 - 10 ** (a1 + a2 - a3 - 1))

posted:
last update: