#P2602. Digit Frequency Count

    ID: 15871 Type: Default 1000ms 256MiB

Digit Frequency Count

Digit Frequency Count

Given two positive integers \(a\) and \(b\), the task is to count the frequency of each digit (from 0 to 9) in all the integers in the interval \([a, b]\) (inclusive). For example, if \(a=1\) and \(b=10\), you need to count the number of times each digit appears when writing down all numbers from 1 to 10.

Note: The input consists of two positive integers. The output should be the counts of the digits 0 through 9 separated by a single space.

The mathematical formulation is as follows:

For each integer \(n \in [a, b]\), let \(f(n, d)\) be the frequency of digit \(d\) in \(n\). Then, the total frequency for digit \(d\) is \[ F(d) = \sum_{n=a}^{b} f(n,d) \quad \text{for } d=0,1,2,\dots,9. \]

inputFormat

The input consists of two positive integers \(a\) and \(b\) (\(a \leq b\)) separated by space or newline.

Example:

1 10

outputFormat

Output a single line containing 10 space-separated integers, where the i-th integer (0-indexed) represents the total number of times digit i appears in all numbers from \(a\) to \(b\).

Example output for the above input:

1 2 1 1 1 1 1 1 1 1

sample

1 10
1 2 1 1 1 1 1 1 1 1