3456. Huge Numbers (Large)

单点时限: 4.0 sec

内存限制: 256 MB

Professor Shekhu has another problem for Akki today. He has given him three positive integers A, N and P and wants him to calculate the remainder when AN! is divided by P. As usual, N! denotes the product of the first N positive integers.

输入格式

The first line of the input gives the number of test cases, T. T lines follow. Each line contains three integers A, N and P, as described above.

  • Limits: 1T100.
  • Small dataset: 1A10,1N10,1P10.
  • Large dataset: 1A105,1N105,1P105.

输出格式

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the answer.

样例

Input
2
2 1 2
3 3 2
Output
Case #1: 0
Case #2: 1

提示

In Sample Case #1, the answer is the remainder when 21!=2 is divided by 2, which is 0.

In Sample Case #2, the answer is the remainder when 33!=36=729 is divided by 2, which is 1.

65 人解决,77 人已尝试。

92 份提交通过,共有 356 份提交。

3.7 EMB 奖励。

创建: 7 年,4 月前.

修改: 7 年,4 月前.

最后提交: 1 年,1 月前.

来源: Kickstart 2017 Round G

题目标签