Feeding the Herrings
Time limit5sMemory limit256 MB
Count ordered triples summing to N with each part at least L and no digit 3 in any part, modulo 12345647.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
Zookeeper Willy is handing out herrings to the seals today. The seals live in three separate pools. The zoo requires its keepers to record what the animals eat, so a touchscreen is installed next to the pools and Willy has to type in the number of herrings he puts into each of the three pools. The screen is broken: it cannot accept the digit 3.
Willy called the chief keeper of marine mammals and asked for help.
"That is fine," said the chief. "Just split the herrings so that the number going into each pool has no digit 3 in it."
"But each pool needs at least herrings," Willy answered. "I might not find a split that works."
"You will find one," said the chief. "With that many herrings in the bucket there are countless possible splits."
"Exactly how many?" Willy wondered to himself.
You are given the total number of herrings and the lower limit on the number of herrings in each pool. Count the splits of the herrings into the three pools in which every pool gets at least herrings, the decimal representation of each of the three numbers contains no digit 3, and the three numbers add up to exactly . Individual herrings are not distinguished, since they are all about the same size and nutrition value. The pools are distinguished, because different groups of seals live in them. No herring can be cut into pieces.
Input
The input holds several test cases. Each case is one line with two integers and (, ) separated by a space, the number of herrings in the bucket and the lower limit on the number of herrings in each pool. A line holding two zeros ends the input.
Output
For each test case print on its own line the number of ways to split the herrings into the three pools, modulo 12345647.