Unlucky Numbers
Time limit1sMemory limit512 MB
Count the n-digit numbers made of digits 0 to k whose digits cannot be split into two groups with equal sums.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
A six-digit bus ticket is usually called lucky if the sum of its first three digits equals the sum of its last three. Vasya, a schoolboy, loved getting lucky tickets, but they came up rarely. So he changed the definition of a lucky ticket.
In his definition, a number is lucky if the sum of some of its digits equals the sum of the remaining digits. Ticket 561743 is lucky because .
Vasya has grown up, but out of habit he still looks for signs of luck in document numbers. He extended his definition to -digit account numbers and other document numbers made of digits from 0 to , where . A number is lucky if the sum of some of its digits equals the sum of the rest. All other numbers are unlucky. Even with the wider definition, many unlucky numbers remain.
Count the unlucky -digit numbers that can be formed from the digits 0 to . Numbers may have any number of leading zeros.
The input file unlucky.in is provided as tests.txt. Create the matching output file for this input and submit it for judging.
Input
The input file contains several pairs of values and , each on its own line.
Output
For each pair of and in the input file, print the count of unlucky numbers on the corresponding line of the output file, or 0 if you cannot obtain the count. The input and output files must have the same number of lines.