This page is still under construction.

Parts of this page are still being built. What you see may change.

App Rating

Interview

Time limit1sMemory limit128 MB

Summary
Given a rounded average rating from 1 to 5, find the minimum number of raters whose exact average rounds to that value.
Level

Medium6 of 10

Topics
Math, Brute force, Binary search, Number theory
Solved
No attempts yet

Problem

The App Store lets users rate an app. Each user gives it from 1 to 5 stars, and the App Store shows the average of all the ratings that have been submitted.

For example, if three users gave 3, 4, and 4 stars, the average rating is 3+4+43=3.67\frac{3 + 4 + 4}{3} = 3.67. (The value is rounded at the third decimal place, leaving two decimals.)

As another example, suppose 126 people rated an app: 53 gave 5 stars, 18 gave 4 stars, 11 gave 3 stars, 16 gave 2 stars, and 28 gave 1 star. Then the average rating is 53×5+18×4+11×3+16×2+28×1126=3.4126984\frac{53 \times 5 + 18 \times 4 + 11 \times 3 + 16 \times 2 + 28 \times 1}{126} = 3.4126984. (The value is rounded at the eighth decimal place, leaving seven decimals.)

For every app he built, Sanggeun stored the number of people who rated it, how many people gave each star count, and the average rating to nn decimal places (0<n<90 < n < 9). One day someone hacked his database and deleted everything except the average rating.

Only the average rating remains. Using it, write a program that finds the minimum number of people who could have rated the app to produce that exact average rating.

Input

The input consists of several lines (at most 2000 lines). Each line contains an average rating vv (1≤v≤51 \le v \le 5) given as a decimal. The fractional part of vv has at least one and at most eight digits, and this number of decimal digits is nn. In other words, vv is the true average rounded at the (n+1)(n+1)-th decimal place.

The last line contains a negative number and must not be processed.

Output

For the ii-th average rating in the input, print the minimum number of people needed to produce it, one per line, in the format Case i: k.

Examples3

  1. Example 1

    Input
    1.15
    4.56316411
    4.56316
    3.67
    3.66
    -1.00
    
    Expected output
    Case 1: 13
    Case 2: 847
    Case 3: 190
    Case 4: 3
    Case 5: 29
    
  2. Example 2

    Input
    1.0
    5.0
    3.00
    2.5
    -1
    
    Expected output
    Case 1: 1
    Case 2: 1
    Case 3: 1
    Case 4: 2
    
  3. Example 3

    Input
    3.4126984
    -1
    
    Expected output
    Case 1: 63