#P10667. Minimum At-Bats Count for a Given Batting Average

    ID: 12694 Type: Default 1000ms 256MiB

Minimum At-Bats Count for a Given Batting Average

Minimum At-Bats Count for a Given Batting Average

In baseball, one of the most fundamental statistics is the batting average. The batting average is defined as the ratio of the number of hits to the number of at‐bats. A "hit" is when a batter strikes the ball such that he reaches at least first base safely. Since a run is scored only when a player returns to home plate, the hit is the most important way to score.

The batting average is computed as:

\(\text{Batting Average} = \frac{h}{d}\)

where \(h\) is the number of hits and \(d\) is the number of at-bats. For example, if a batter gets 1 hit in 5 at-bats, his batting average is \(0.2\).

Uruto, an amateur baseball fan, once noticed his batting average data from practice. He observed that this batting average value had been rounded to \(n\) decimal places using the standard rounding rule (i.e. round half up). Uruto is now curious about the minimum number of at-bats \(d\) he must have had so that there exists an integer number \(h\) (with \(0 \le h \le d\)) such that when the ratio \(\frac{h}{d}\) is rounded to \(n\) decimal places it becomes the given value.

More formally, let the given rounded batting average be \(v\) and let \(\varepsilon = 0.5\times10^{-n}\). Then there must exist an integer \(h\) (with \(0 \le h \le d\)) such that:

\(v - \varepsilon \le \frac{h}{d} < v + \varepsilon\)

Your task is to compute the smallest positive integer \(d\) (i.e. the minimum number of at-bats) for which such an \(h\) exists.

inputFormat

The input consists of two lines:

  • The first line contains an integer \(n\) representing the number of decimal places to which the batting average was rounded.
  • The second line contains a decimal number \(v\) (with exactly \(n\) decimal places) representing the rounded batting average.

outputFormat

Output a single integer representing the minimum number of at-bats \(d\) such that there exists an integer number of hits \(h\) (with \(0 \le h \le d\)) for which the ratio \(\frac{h}{d}\) rounds to \(v\) when rounded to \(n\) decimal places (using the standard round half up rule).

sample

1
0.2
5