atcoder#ARC149A. [ARC149A] Repdigit Number
[ARC149A] Repdigit Number
Score : points
Problem Statement
You are given positive integers and . Find the maximum positive integer that satisfies all of the following conditions.
- is a positive integer less than , and all digits in the decimal representation of are the same.
- is a multiple of .
If no positive integer satisfies the conditions, print -1
.
Constraints
Input
The input is given from Standard Input in the following format:
Output
Print the maximum positive integer that satisfies all of the conditions, or -1
if no such positive integer exists.
7 12
888888
Four positive integers satisfy the conditions: . The answer is the maximum of them, which is .
9 12
888888888
Six positive integers satisfy the conditions: .
1 3
9
Three positive integers satisfy the conditions: .
1000 25
-1
No positive integers satisfy the conditions.
30 1
999999999999999999999999999999