#P5261. [JSOI2013] 数字理论

    ID: 5991 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>2013各省省选江苏O2优化

[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