#P5261. [JSOI2013] 数字理论

[JSOI2013] 数字理论

Problem Description

Given four positive integers K, S, P, DK,~S,~P,~D, in decimal, find the smallest KK-digit natural number xx such that the sum of digits of xx is SS, and the sum of digits of x×Dx \times D is PP.

Input Format

The input contains one line with four integers: K, S, P, DK,~S,~P,~D.

Output Format

Output one integer in one line, representing the smallest natural number xx that satisfies the conditions. If it does not exist, output 1-1.

2 9 9 5
18

Hint

Constraints: $1~\leq~K~\leq~100,~1~\leq~S,~P~\leq~1000,~1~\leq~D~\leq~9$.

Translated by ChatGPT 5