| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 1801 | Accepted: 698 |
Description
Tired of the Tri Tiling game finally, Michael turns to a more challengeable game, Quad Tiling:
In how many ways can you tile a 4 × N (1 ≤ N ≤ 109) rectangle with 2 × 1 dominoes? For the answer would be very big, output the answer modulo M (0 < M ≤ 105).
Input
Input consists of several test cases followed by a line containing double 0. Each test case consists of two integers, N and M, respectively.
Output
For each test case, output the answer modules M.
Sample Input
1 10000 3 10000 5 10000 0 0
Sample Output
1 11 95
Source
本文探讨了如何解决QuadTiling游戏中用2×1骨牌覆盖4×N矩阵的问题。通过构建16×16矩阵表示状态转移,并利用快速幂运算优化计算过程,解决了大规模输入情况下的效率问题。
1161

被折叠的 条评论
为什么被折叠?



