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

#GL0000300. Số chỉ gồm chữ số 1 (Ones)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Số chỉ gồm chữ số 1 (Ones)

Ones

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Consider the positive decimal integers consisting exclusively of digit 1:

1,11,111,1111,…1,11,111,1111,\ldots

You are given a positive integer nn that is divisible by neither 22 nor 55. Under this condition, some number in the sequence is divisible by nn.

Find the minimum number of digits of such a number. Output its length, not the potentially enormous integer itself.

Input

A single line containing positive integer nn.

Output

Print one positive integer: the minimum number of digit 1 characters required.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1001\le n\le 100; gcd⁡(n,10)=1\gcd(n,10)=1.
  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000; gcd⁡(n,10)=1\gcd(n,10)=1.
  • Subtask 3 (50 points): 1≤n≤100001\le n\le 10000; gcd⁡(n,10)=1\gcd(n,10)=1.

Examples

Examples 1

Input

3

Output

3

Explanation

Neither 11 nor 1111 is divisible by 33, but 111=3⋅37111=3\cdot37, so the minimum length is 33.

Examples 2

Input

7

Output

6

Explanation

The six-digit repunit is 111111=7⋅15873111111=7\cdot15873. Lengths 11 through 55 have nonzero remainder, so the answer is 66.

Examples 3

Input

9901

Output

12

Explanation

A 12-digit repunit is divisible by 99019901, and no shorter repunit has remainder zero modulo 99019901.