Decimal Representation Length

No attempts yetTime limit1sMemory limit128 MB

Problem

Every rational number can be written in decimal notation. Wrapping the repeating digits in parentheses gives representations like these:

4/2 = 2
1/4 = 0.25
10/3 = 3.(3)
1/7 = 0.(142857)
1/45 = 0.0(2)

Each one needs a different number of characters. 4/2=24/2 = 2 needs one character, and 1/7=0.(142857)1/7 = 0.(142857) needs 10. Count only the representation to the right of the equals sign, including the digits, the decimal point, and the parentheses. An integer value carries no decimal point, and a value that terminates carries no parentheses. Both the non-repeating prefix and the repeating block are taken as short as possible.

You are given an integer nn. What is the greatest number of characters needed to write a fraction a/ba/b with 1a,bn1 \le a, b \le n this way?

Input

The input holds several test cases. Each test case is a single integer nn (1n5001 \le n \le 500) on its own line. The last line holds a single 00.

Output

For each test case, print one integer on its own line: the greatest number of characters needed to write a/ba/b for any 1a,bn1 \le a, b \le n. Print no spaces and no blank lines.