#Lutece0287. Yang Hui Triangle

Yang Hui Triangle

Migrated from Lutece 287 Yang Hui Triangle

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Harry is a Junior middle student. He is very interested in the story told by his mathematics teacher about the Yang Hui triangle in the class yesterday. After class he wrote the following numbers to show the triangle our ancestor studied.

title

He found many interesting things in the above triangle. It is symmetrical, and the first and the last numbers on each line is 11; there are exactly ii numbers on the line ii.

Then Harry studied the elements on every line deeply. Of course, his study is comprehensive.

Now he wanted to count the number of elements which are the multiple of 33 on each line. He found that the numbers of elements which are the multiple of 33 on line 2,3,4,5,6,7,2, 3, 4, 5, 6, 7, \cdots are 0,0,2,1,0,4,0, 0, 2, 1, 0, 4, \cdots So the numbers of elements which are not divided by 33 are 2,3,2,4,6,3,,2, 3, 2, 4, 6, 3, \cdots , respectively. But he also found that it was not an easy job to do so with the number of lines increasing. Furthermore, he is not satisfied with the research on the numbers divided only by 33. So he asked you, an erudite expert, to offer him help. Your kind help would be highly appreciated by him.

Since the result may be very large and rather difficult to compute, you only need to tell Harry the last four digits of the result.

Input

There are multiple test cases in the input file. Each test case contains two numbers PP and N,(P<1000,N109)N, (P < 1000, N \leq 10^9), where PP is a prime number and NN is a positive decimal integer.

P=0,N=0P = 0, N = 0 indicates the end of input file and should not be processed by your program.

Output

For each test case, output the last four digits of the number of elements on the N+1N + 1 line on Yang Hui Triangle which can not be divided by PP in the format as indicated in the sample output.

Samples

3 4
3 48
0 0
Case 1: 0004
Case 2: 0012

Note

The data used in this problem is unofficial data prepared by GreenWall. So any mistake here does not imply mistake in the offcial judge data.

Resources

Shanghai 2006