#P7437. [2017年杭电多校]Division Game

[2017年杭电多校]Division Game

Division Game

Problem Description

There are kk piles of stones in a circle, numbered from 00 to k1k - 1, where the number of the stones in each pile is nn initially. You can do some round operations, where the initial round is numbered as the 11-st round. The operation of the ii-th round is to modify the pile of stones numbered (i1)modk(i - 1) \bmod k. In each round, you should remove from this pile some stones (at least one stone), satisfying that the number of stones in this pile before this operation is a multiple of the number of stones in this pile after operation, which means that you ought to remain at least one stone in this pile. The game is ended if there exists at least one pile containing only one stone. Given two positive integers nn and kk, your task is to calculate for each pile the number of the possible operation plans that it is the last operated pile before the game is ended. The integer nn may be very large, so the prime-factor decomposition of nn will be given, in other words, if n=i=1mpiein = \prod_{i = 1}^{m}{p_i^{e_i}}, then the integers mm and (pi,ei)(p_i, e_i) (1im)(1 \leq i \leq m) will be given, but the integer nn will not. The answer may be very large, so you only need to give the value of the answer modulo 985661441985661441.

Input

The input contains multiple test cases. For each test case: The first line contains two positive integers mm and kk, satisfying that 1m,k101 \leq m, k \leq 10. In next mm lines, the ii-th line contains two positive integers pip_i and eie_i, satisfying that 2pi109,2 \leq p_i \leq 10^9, ei1,e_i \geq 1, i=1mei105\sum_{i = 1}^{m}{e_i} \leq 10^5. It is guaranteed that p1,p2,,pmp_1, p_2, \cdots, p_m are distinct. About 200200 test cases in total, where no more than 55 cases satisfy i=1mei104\sum_{i = 1}^{m}{e_i} \geq 10^4.

Output

For each test case, output " Case #xx: y0y_0 y1y_1 \cdots yk1y_{k - 1} " in one line (without quotes), where xx indicates the case number starting from 11 and yiy_i (0i<k)(0 \leq i < k) denotes the number of the possible operation plans modulo 985661441985661441 for the pile numbered ii of corresponding case.

Sample Input

1 1

2 2

2 1

3 1

5 1

1 2

2 3

2 2

2 4

5 4

Sample Output

Case #1: 2

Case #2: 3

Case #3: 6 4

Case #4: 1499980 1281085

Source

2017 Multi-University Training Contest - Team 1

https://acm.hdu.edu.cn/showproblem.php?pid=6036