Decimal Representation Length
Time limit1sMemory limit128 MB
For each n, report the longest decimal writing among all fractions a/b with a and b from 1 to n, where the count includes digits, the point, and parentheses.
- Level
Medium5 of 10
- Topics
- Simulation, Hash map, Brute force, Math
- Solved
- No attempts yet
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. needs one character, and 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 . What is the greatest number of characters needed to write a fraction with this way?
Input
The input holds several test cases. Each test case is a single integer () on its own line. The last line holds a single .
Output
For each test case, print one integer on its own line: the greatest number of characters needed to write for any . Print no spaces and no blank lines.