PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000305. Số chỉ gồm một chữ số (Integer Divisibility)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn and dd, where dd is a decimal digit from 11 to 99. It is guaranteed that nn is divisible by neither 22 nor 55.

Consider the positive integers consisting entirely of the digit dd in decimal notation: dd, dddd, dddddd, and so on. Find the minimum number of digits of such an integer divisible by nn.

For example, when n=7n=7 and d=3d=3, the number 333333333333 is divisible by 77, so the answer is 66. Print only its length, not the possibly enormous number itself.

Input

The only line contains nn and dd: the divisor and the allowed digit.

Output

Print one integer: the minimum length of a positive decimal integer consisting solely of digit dd and divisible by nn.

Subtasks

  • Subtask 1 (20 points): 1≤n≤3001\le n\le300; n mod 2≠0n\bmod2\ne0; n mod 5≠0n\bmod5\ne0; 1≤d≤91\le d\le9.
  • Subtask 2 (30 points): 1≤n≤1041\le n\le10^4; n mod 2≠0n\bmod2\ne0; n mod 5≠0n\bmod5\ne0; 1≤d≤91\le d\le9.
  • Subtask 3 (50 points): 1≤n≤1061\le n\le10^6; n mod 2≠0n\bmod2\ne0; n mod 5≠0n\bmod5\ne0; 1≤d≤91\le d\le9.

Examples

Example 1

Input

3 1

Output

3

Explanation

Try lengths in order: 1 mod 3=11\bmod3=1, 11 mod 3=211\bmod3=2, and 111 mod 3=0111\bmod3=0. The first zero remainder occurs at length 33.

Example 2

Input

7 3

Output

6

Explanation

For lengths 11 through 66, the remainders of 3,33,333,3333,33333,3333333,33,333,3333,33333,333333 modulo 77 are 3,5,4,1,6,03,5,4,1,6,0. The first divisible number has 66 digits.

Example 3

Input

9901 1

Output

12

Explanation

Append digit 11 repeatedly and track only the remainder. The first zero remainder occurs after 1212 digits, so there is no need to construct the entire twelve-digit number.