ZZLDUSP36F66GUAMMCV6DA2PBJFUNGUJKACYI5UWJKIXNDZZ4KSAC
fn digits(a: usize) -> usize {
((a as f64).log10() as usize) + 1
fn range_digits(base: usize, range: Range<usize>) -> usize {
let (mut result, mut power, mut current_digits) = (0, 1, 0);
while power <= range.start {
power *= base;
current_digits += 1;
}
result += (power - range.start) * current_digits;
while power <= range.end {
let last_power = power;
power *= base;
current_digits += 1;
result += (power - last_power) * current_digits;
}
result -= (power - range.end) * current_digits;
result
// Present conversions and type casts could be problematic for certain inputs.
fn range_digits(start: usize, end: usize) -> usize {
let (start_digits, end_digits) = (digits(start), digits(end));
let (a, b) = (
10_usize.pow(start_digits.try_into().unwrap()) - 1,
10_usize.pow((end_digits - 1).try_into().unwrap()) as usize,
);
(digits(a + 1)..=digits(b - 1)).fold(0, |acc, elem| {
acc + 9 * elem * 10_usize.pow((elem - 1).try_into().unwrap())
}) + ((a - start + 1) * start_digits)
+ ((end - b + 1) * end_digits)
}
+ range_digits(3, s as usize)
+ match e {
0 => LENGTHS[0] + LENGTHS[1] + LENGTHS[2],
1 => LENGTHS[1] + LENGTHS[2],
2 => LENGTHS[2],
_ => 0,
}
+ range_digits(
10,
Range {
start: 3,
end: (s + 1) as usize,
},
) + match e {
0 => LENGTHS[0] + LENGTHS[1] + LENGTHS[2],
1 => LENGTHS[1] + LENGTHS[2],
2 => LENGTHS[2],
_ => 0,
}