Dream Counting
Time limit1sMemory limit128 MB
Count how many times each decimal digit 0 through 9 appears when writing every integer from M to N.
- Level
Medium5 of 10
- Topics
- Math, Brute force, Implementation, Number theory
- Solved
- No attempts yet
Problem
Bessie the cow was daydreaming, drifting between wakefulness and that pleasant drowsiness we all feel when we are tired. Unable to fall asleep, she counted numbers instead of sheep. Bessie's mind is razor sharp, so as she counts she pictures every number vividly and starts noticing its digits. She wonders: while counting through a run of consecutive integers, how many times does each digit appear?
Given two integers and , consider every integer from to inclusive. For each digit from to , count how many times that digit appears across the decimal representations of all of these numbers.
Constraints:
Input
- Line 1: Two space-separated integers, and .
Output
- Line 1: Ten space-separated integers. The -th integer (for from to ) is the number of times digit appears while writing out every integer from to .