Just Too Lucky
Time limit3sMemory limit256 MB
Count integers from 1 to n (up to 10^12) whose value is divisible by its own digit sum, requiring digit-DP over fixed digit-sum targets.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
Ever since public transit was invented, passengers have looked for lucky ticket numbers. There are many definitions of a lucky ticket: sometimes a ticket is lucky when the sum of the first half of its digits equals the sum of the second half, sometimes the products of the digits are compared, and so on.
In the city of St Andrewburg the tickets are numbered with the integers from to . Bill calls a ticket lucky when its number is divisible by the sum of its digits. Help Bill count how many lucky tickets there are.
For example, ticket is lucky, because its digit sum is and is divisible by .
Input
The only line contains a single integer ().
Output
Print a single integer — the number of lucky tickets among .