Count Substrings Divisible By Last Digit
For each end digit, count starts whose substring is divisible by that digit, using digit sums for 3 and 9, the last three digits for 2, 4, 5 and 8, and prefix residues for 6 and 7.
For each end digit, count starts whose substring is divisible by that digit, using digit sums for 3 and 9, the last three digits for 2, 4, 5 and 8, and prefix residues for 6 and 7.