N! mod P (2)
Time limit3sMemory limit1024 MB
Given N and a prime P with N < P, compute N! modulo P.
- Level
Easy3 of 10
- Topics
- Implementation, Math
- Solved
- No attempts yet
Problem
Given a positive integer N and a prime P greater than N, find the remainder of N! divided by P.
Input
The first line gives N and P separated by a space.
Output
Print the remainder of N! divided by P.
Constraints
- 1 ≤ N < P ≤ 10^9
- P is prime
Hint
The intended solution written by the problem setter runs in about 150ms.