C. 【例50.3】 平衡数

    Type: Default 1000ms 64MiB

【例50.3】 平衡数

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Description

A balanced number is a positive integer xx where each digit dd appears exactly dd times in xx. For example, x=122x=122 is a balanced number because:
For the hundreds digit d=1d = 1, the digit 11 appears exactly 11 time in 122122, satisfying the condition;
For the tens digit d=2d = 2, the digit 22 appears exactly 22 times in 122122, satisfying the condition;
For the ones digit d=2d = 2, the digit 22 appears exactly 22 times in 122122, satisfying the condition;
Since every digit in 122122 satisfies the condition, 122122 is a balanced number.
Given two positive integers ll and rr (lrl≤r), please help calculate the sum of all balanced numbers between ll and rr.

Input Format

One line containing two positive integers ll and rr (1lr100001≤l≤r≤10000), separated by a space.

Output Format

One line containing a single integer, representing the sum of all balanced numbers between ll and rr.

Sample

1 25
23

20251129 B班作业(8)

Not Claimed
Status
Done
Problem
6
Open Since
2025-11-29 0:00
Deadline
2025-12-7 23:59
Extension
24 hour(s)