Another Factorial Problem
All submissions for this problem are available.
Every programming contest has a problem on factorials. Continuing with this tradition, we decided to include one too.
Given two integers, n and p, find x (mod p) where x is the number obtained after eliminating all powers of p from n!.
Here n! denotes factorial of n. Assume that p is prime.
The first line of the input contains an integer T denoting the number of test cases. This is followed by T lines each containing two space separated integers, n and p.
One line for each test case, giving the value of the required expression.
- T ≤ 10
- 1 ≤ n ≤ 1018
- 1 ≤ p ≤ 107
Input: 1 5 3 Output: 1
|Time Limit:||1.27443 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, JAVA, GO|
Fetching successful submissions