Smallest Repunit Divisible by K

Given an integer K, find the length of the smallest positive integer made only of digit 1 that is divisible by K. Return -1 if no such number exists.

Input Format

K = positive integer

Output Format

length of the smallest repunit divisible by K, or -1

Constraints

  • 1 <= K <= 10^5

Examples

Example 1:

Input:

K = 1

Output:

1

Explanation:

1 is divisible by 1.

Example 2:

Input:

K = 3

Output:

3

Explanation:

111 is divisible by 3.

Loading...
Smallest Repunit Divisible by K - Math