A Nod 1008 n factorial mod P "java big number messed up"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.