Nyoj28 Big Data factorial

Source: Internet
Author: User
Big Data factorial time limit: 3000 MS | memory limit: 65535 kb difficulty: 3
Description
We all know how to calculate a factorial of a number. But if this number is large, how should we calculate it and output it?

Input
Enter an integer m (0 <m <= 5000)
Output
Output the factorial of M, and enter a linefeed after the output ends.
Sample Input
50
Sample output
30414093201713378043612608166064768844377641568960512000000000000

 #include<iostream>#include<cstring>#include<cstdio>using namespace std;int main(){int a[17500]={0,1};int m,i,j,len=1,tem,jin;cin>>m;for(i=2;i<=m;i++){jin=0;for(j=1;j<=len;j++){tem=a[j]*i+jin;a[j]=tem%10;jin=tem/10;if(j==len&&jin!=0) len++;}}for(i=len;i>=1;i--) cout<<a[i];cout<<endl;return 0;}        

Related Article

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.