#P16634. [GKS 2017 #G] Huge Numbers

    ID: 18990 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学2017数论欧拉降幂欧拉函数Google Kick Start

[GKS 2017 #G] Huge Numbers

Problem Description

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.

Input Format

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.

Output Format

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

Hint

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

1T1001 \le T \le 100.

Small dataset (Test set 1 - Visible)

1A101 \le A \le 10.

1N101 \le N \le 10.

1P101 \le P \le 10.

Large dataset (Test set 2 - Hidden)

1A1051 \le A \le 10^5.

1N1051 \le N \le 10^5.

1P1051 \le P \le 10^5.