#GL0000305. Số chỉ gồm một chữ số (Integer Divisibility)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số chỉ gồm một chữ số (Integer Divisibility)
Integer Divisibility
Source: LightOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given positive integers and , where is a decimal digit from to . It is guaranteed that is divisible by neither nor .
Consider the positive integers consisting entirely of the digit in decimal notation: , , , and so on. Find the minimum number of digits of such an integer divisible by .
For example, when and , the number is divisible by , so the answer is . Print only its length, not the possibly enormous number itself.
Input
The only line contains and : the divisor and the allowed digit.
Output
Print one integer: the minimum length of a positive decimal integer consisting solely of digit and divisible by .
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Example 1
Input
3 1
Output
3
Explanation
Try lengths in order: , , and . The first zero remainder occurs at length .
Example 2
Input
7 3
Output
6
Explanation
For lengths through , the remainders of modulo are . The first divisible number has digits.
Example 3
Input
9901 1
Output
12
Explanation
Append digit repeatedly and track only the remainder. The first zero remainder occurs after digits, so there is no need to construct the entire twelve-digit number.