Hangzhou Electric HDU 1042 N!

Source: Internet
Author: User

N! Time limit:10000/5000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 61718 Accepted Submission (s): 17632


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

Authorjgshining (Aurora Dazzle) will not do at first but finally can understand the algorithm of large number factorial!
#include <iostream>using namespace Std;int main () {int ls[10001];int n,i,j;while (cin>>n) {int m=0;ls[0]=1; for (i=1;i<=n;i++) {int temp=0;for (j=0;j<=m;j++) {ls[j]=ls[j]*i+temp;temp=ls[j]/10000;ls[j]=ls[j]%10000;} if (temp) {    ls[++m]=temp;}} cout<<ls[m];for (int k=m-1;k>=0;k--) printf ("%04d", Ls[k]); Cout<<endl;} return 0;}

Hangzhou Electric HDU 1042 N!

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.