#P5282. 【模板】快速阶乘算法
【模板】快速阶乘算法
Description
You are given a positive integer and a prime . You need to compute:
There are test cases.
Input Format
The first line contains a positive integer , the number of test cases.
The next lines each contain two positive integers , with the meaning described above.
Output Format
Output lines, each being the answer for one test case.
4
16777216 998244353
72267859 998244353
2333333 19260817
1919810 2147481811
789885751
569626621
16351109
1416439247
Hint
Constraints:
For of the testdata: .
For another of the testdata: .
For of the testdata: , .
It is guaranteed that is prime.
[Hint]
Please make sure your algorithm runs in no more than time complexity. The time limit is more than ten times that of the std.
Translated by ChatGPT 5
京公网安备 11011102002149号