Time Limit: 4 second(s) | Memory Limit: 32 MB |
All of you must have heard the name of the planet Krypton. If you can't remember the planet, don't worry. Planet Krypton is the origin of Superman that means the mother planet where Superman was born. Superman was sent to earth by his parents when the planet was about to explode. Legends say that only few people of the planet survived from that explosion.
The inhabitants of the planet are called 'Kryptonians'. Kryptonians, though otherwise completely human, were superior both intellectually and physically to natives of Earth. One of the most common differences is their number system. The number system is denoted below:
1) The base of the number system is unknown, but legends say that the base lies between 2 and 6.
2) Kryptonians don't use a number where two adjacent digits are same. They simply ignore these numbers. So, 112 is not a valid number in Krypton.
3) Numbers should not contain leading zeroes. So, 012 is not a valid number.
4) For each number, there is a score. The score can be found by summing up the squares of differences of adjacent numbers. For example 1241 has the score of
5) (1-2)^{2} + (2-4)^{2} + (4-1)^{2} = 1 + 4 + 9 = 14.
6) All the numbers they use are integers.
Now you are planning to research on their number system. So, you assume a base and a score. You have to find, how many numbers can make the score in that base.
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case contains two integers denoting base (2 ≤ base ≤ 6) and score (1 ≤ score ≤ 10^{9}). Both the integers will be given in decimal base.
For each case print the case number and the result modulo 2^{32}. Check the samples for details. Both the case number and result should be reported in decimal base.
Sample Input |
Output for Sample Input |
2 6 1 5 5 |
Case 1: 9 Case 2: 80 |
Developed and Maintained by
JANE ALAM JAN |
Copyright © 2012
LightOJ, Jane Alam Jan |