1008 N's factorial mod P
Base time limit: 1 seconds space limit: 131072 KB score: 0 Difficulty: Basic question input N and p (p is prime), N! Mod P =? (Mod is modulo%) For example: n = ten, P = 11,10! = 36288003628800% = 10Input
Two number n,p, separated by a space in the middle. (N < 10000, P < 10^9)
Output
Output n! The result of mod p.
Input example
10 11
Output example
10
Topic Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1008 Analysis: Learn a simple Java, to experience a wave of Java's cool sense, Java Dafa really good ah! The AC code is given below:
1 ImportJava.math.BigInteger;2 ImportJava.util.Scanner;3 4 5 Public classSSS {6 7 /**8 * @paramargs9 */Ten Public Static voidMain (string[] args) { One //TODO auto-generated Method Stub AScanner in=NewScanner (system.in); -BigInteger sum=Biginteger.one; - intN; then=in.nextint (); -BigInteger p=In.nextbiginteger (); - for(inti=1;i<=n;i++) -sum=sum.multiply (biginteger.valueof (i)); + System.out.println (Sum.remainder (P)); - } +}
A Nod 1008 n factorial mod P "java big number messed up"