We have come up with a wonderful problem for Google Code Jam 2010 that involves contestants solving a cryptarithm. But we need your help in creating testcases for the problem; more precisely, we're concerned with addition equations that are good enough (in the sense defined below) for conversion into cryptarithms.
You don't need to know what a cryptarithm is to solve this problem, as we'll provide all required definitions. We define a cryptarithm equation to be an addition equation written in such a way that all summands (numbers being added) and the sum are aligned to the same right border like this:
124
3125
180
Note that summands in a cryptarithm equation are always positive and written without leading zeros. The order of summands is not important (in other words, two equations which differ only in the order of the summands are considered the same).
The example above was in base 10, but we're also interested in cryptarithm equations in other bases. Note that a "digit" in base b could mean any integer between 0 and b-1. Here is a cryptarithm equation in base 23:
I7BJJJ
1F47
How many cryptarithm equations are there with the given sum N in the given base B?
Since the answer might be very large, please output it modulo 1000000007.
The first line of the input gives the number of test cases, T (1<=T<=20). T lines follow. Each contains two positive integers N(1<=N<=1018) and B(2<=B<=50). All input numbers are given in base 10.
For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of different cryptarithm equations with the given sum. Since this number can be very big, please output it modulo 1000000007. Of course, the output itself should be in base 10.
2 6 10 8 4
Case #1: 4 Case #2: 4
Migrated from old NTUJ.
GCJ Round3 pD
No. | Testdata Range | Score |
---|