Responsive image

问题 1789 --Division Game

1789: Division Game

时间限制: 10 Sec  内存限制: 128 MB
提交: 2  解决: 1
[提交][状态][讨论版][命题人:]

题目描述

There are k piles of stones in a circle, numbered from 0 to k−1, where the number of the stones in each pile is n initially. You can do some round operations, where the initial round is numbered as the 1-st round.

The operation of the i-th round is to modify the pile of stones numbered (i−1)modk. 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 n and k, 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 n may be very large, so the prime-factor decomposition of n will be given, in other words, if n=∏mi=1peii, then the integers m and (pi,ei) (1≤i≤m)will be given, but the integer n will not.

The answer may be very large, so you only need to give the value of the answer modulo 985661441.

输入描述

The input contains multiple test cases.

For each test case:

The first line contains two positive integers m and k, satisfying that 1≤m,k≤10.

In next m lines, the i-th line contains two positive integers pi and ei, satisfying that 2≤pi≤109, ei≥1, ∑mi=1ei≤105.

It is guaranteed that p1,p2,⋯,pm are distinct.

About 200 test cases in total, where no more than 5 cases satisfy ∑mi=1ei≥104.

输出描述

For each test case, output "Case #x: y0 y1 ⋯ yk−1" in one line (without quotes), where x indicates the case number starting from 1 and yi (0≤i<k) denotes the number of the possible operation plans modulo 985661441 for the pile numbered i of corresponding case.

样例输入

1 1
2 2
2 1
3 1
5 1
1 2
2 3
2 2
2 4
5 4

样例输出

Case #1: 2
Case #2: 3
Case #3: 6 4
Case #4: 1499980 1281085

来源

 

[提交][状态]
ACM算法攻关部