Count ordered triples summing to N with each part at least L and no digit 3 in any part, modulo 12345647.
Hard8Dynamic programmingCombinatoricsMathNo attempts yetTime limit5sMemory limit256 MBZookeeper 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 L 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 N of herrings and the lower limit L on the number of herrings in each pool. Count the splits of the N herrings into the three pools in which every pool gets at least L herrings, the decimal representation of each of the three numbers contains no digit 3, and the three numbers add up to exactly N. 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.
The input holds several test cases. Each case is one line with two integers N and L (1≤N≤1010000, 1≤L≤N/3) 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.
For each test case print on its own line the number of ways to split the herrings into the three pools, modulo 12345647.