CF BUDDY
← Problems·

1070A · Find a Number

2200 · dp, graphs, number theory

Problem: You are given two positive integers dd and ss. Find minimal positive integer nn which is divisible by dd and has sum of digits equal to ss.

Input Format: The first line contains two positive integers dd and ss (1d500,1s50001 \le d \le 500, 1 \le s \le 5000) separated by space.

Output Format: Print the required number or -1 if it doesn't exist.

Sample Cases

Case 1

Input

13 50

Output

699998

Case 2

Input

61 2

Output

1000000000000000000000000000001

Case 3

Input

15 50

Output

-1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback