14: Calculate the factorial of n less than 10000, And the factorial of 1410000

Source: Internet
Author: User

14: Calculate the factorial of n less than 10000, And the factorial of 1410000
14: Calculate the factorial of n less than 10000

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
5000 ms
 
Memory limit:
655360kB
Description

Calculate the factorial of n less than 10000.

Input
Only one line of input, integer n (0 <=n <= 10000 ).
Output
One row, that is, n! .
Sample Input
100
Sample output
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
Source
JP06
 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 using namespace std; 6 int a[1000001]={1}; 7 int ans[10000001]={1}; 8 char n[1001]; 9 int en[1001];10 int main()11 {12     int n;13     cin>>n;14     int lans=1;15     int x=0;16     for(int i=1;i<=n;i++)17     {18         19         for(int j=0;j<lans;j++)20         {21             a[j]=a[j]*i+x;22             x=a[j]/10;23             if(x>0&&j==lans-1)24             lans++;25             a[j]=a[j]%10;26         }27     }28     int flag=0;29     for(int i=lans;i>=0;i--)30     {31         if(a[i]==0&&flag==0)32         continue;33         else flag=1;34         cout<<a[i];35     }36     return 0;37 }

 

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.