#P16634. [GKS 2017 #G] Huge Numbers

    ID: 16901 Type: RemoteJudge 2000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>数学2017数论欧拉降幂欧拉函数Google Kick Start

[GKS 2017 #G] Huge Numbers

题目描述

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

输入格式

The first line of the input gives the number of test cases, TT. TT lines follow. Each line contains three integers AA, NN and PP, as described above.

输出格式

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

2
2 1 2
3 3 2
Case #1: 0
Case #2: 1

提示

In Sample Case 11, the answer is the remainder when 21!=22^{1!} = 2 is divided by 22, which is 00.

In Sample Case 22, the answer is the remainder when 33!=36=7293^{3!} = 3^6 = 729 is divided by 22, which is 11.

Limits

1≤T≤1001 \le T \le 100.

Small dataset (Test set 1 - Visible)

1≤A≤101 \le A \le 10.

1≤N≤101 \le N \le 10.

1≤P≤101 \le P \le 10.

Large dataset (Test set 2 - Hidden)

1≤A≤1051 \le A \le 10^5.

1≤N≤1051 \le N \le 10^5.

1≤P≤1051 \le P \le 10^5.