HDU limit 2-N! (Large number)

Source: Internet
Author: User
N! Time Limit: 10000/5000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 54761 accepted submission (s): 15578


Problem descriptiongiven an integer N (0 ≤ n ≤ 10000), your task is to calculate n!
 
Inputone N in one line, process to the end of file.
 
Outputfor each n, output n! In one line.
 
Sample Input
123
 
Sample output
126 calculate the factorial of less than 10000. Java + brute force...
import java.io.*;import java.util.*;import java.math.*;public class Main {       public static void main(String[] args){       Scanner in=new Scanner(System.in);       int n,i;BigInteger ans,t;       while(in.hasNext()){       n=in.nextInt();       ans=new BigInteger("1");       for(i=1;i<=n;i++){       t=new BigInteger(Integer.toString(i));       ans=ans.multiply(t);       }       System.out.println(ans);       }       }}

HDU limit 2-N! (Large number)

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.