N! mod P (1)
Time limit3sMemory limit1024 MB
Given N and a prime P larger than N, compute N! modulo P.
- Level
Easy2 of 10
- Topics
- Math, Implementation, Number theory, Brute force
- Solved
- No attempts yet
Problem
Given a positive integer and a prime greater than , find the remainder when is divided by .
Input
The first line contains and separated by a space.
Output
Find the remainder when is divided by .
Constraints
- is prime
Hint
The solution the setter intended and wrote runs in about 1500ms.
The fast solution the setter wrote runs in about 60ms.