#P8140. Optimizing Bundle Price Trailing Digits

    ID: 21322 Type: Default 1000ms 256MiB

Optimizing Bundle Price Trailing Digits

Optimizing Bundle Price Trailing Digits

You are given a doodad with a fixed price of b cents and a target trailing digit d (0–9). You can sell these doodads in bundles. In a bundle of size k, the total price is k × b cents. However, your marketing department requires that the total bundle price does not exceed a cents.

Your task is to choose a positive integer k (with k × b ≤ a) so that the total price k × b has as many consecutive trailing occurrences of the digit d as possible. In case of a tie, choose the bundle with the smallest total price. Output the chosen bundle size k and the corresponding total price.

For example, if a = 400, b = 57 and d = 9, then choosing k = 7 gives a bundle price of 399 cents, which ends with two consecutive 9's, whereas a single doodad (57 cents) has no trailing 9.

Note: In any formulas below, use LaTeX notation. For instance, the product is defined as \(k \times b\) and the constraint as \(k \times b \le a\).

inputFormat

The input consists of a single line containing three integers a, b, and d separated by spaces:

  • a: the maximum allowed bundle price (in cents).
  • b: the price of a single doodad (in cents).
  • d: the desired trailing digit (0–9) for the bundle price.

You may assume that \(a \ge b\).

outputFormat

Print two integers separated by a space:

  • k: the chosen bundle size.
  • The bundle price, i.e. \(k \times b\) (in cents).

sample

400 57 9
7 399