#209. 递归计数特殊8
递归计数特殊8
Count Eights Recursively
Background
Congcong is learning recursion, and Dawei has assigned him an interesting digit counting task.
Problem Description
Given a non-negative integer , compute recursively (no loops) the count of the occurrences of as a digit. Except that an with another immediately to its left counts double, so yields . Note that mod () by yields the rightmost digit ( is ), while divide () by removes the rightmost digit ( is ).
Input Format
Input is given from Standard Input in the following format.
Output Format
Output is printed to Standard Output in the following format.
The total count of occurrences of .
Sample
8
1
818
2
8818
4
Sample Explanation
For input :
- The rightmost (units digit) has no to its left, counts as .
- The digit does not count.
- The second from the left (hundreds digit) has an to its left (thousands digit), so it counts as .
- The leftmost (thousands digit) has no digit to its left, counts as . Total count is .
Constraints
Time limit: 1 second, Memory limit: 1024 KiB