← ALL NOTES
Math

3871. Count Commas in Range II

A number's comma count depends only on how many digits it has: a d-digit number carries floor((d-1)/3) commas. So I group the range [1, n] by digit length and multiply each group's size by the commas that length contributes, instead of walking every integer up to 10^15.

Loading…