Nyoj 28 Large number factorial

Source: Internet
Author: User

Large number factorial time limit:MS | Memory limit:65535 KB Difficulty:3
Describe
we all know how to calculate the factorial of a number, but if the number is large, how do we calculate it and output it?
Input
Enter an integer m (0<m<=5000)
Output
the factorial of the output m and enter a newline character after the output ends
Sample input
50
Sample output
30414093201713378043612608166064768844377641568960512000000000000

Simulation questions:
1#include <stdio.h>2#include <string.h>3 #defineN 10000104 intA[n];5 intImitation (intN)6 {7     inti;8      for(i=0; a[i]>=0; i++)9     {Tena[i]*=N; One     } A      for(i=0; a[i]>=0; i++) -     { -         if(a[i]>=Ten) the         { -             if(a[i+1]<0) -a[i+1]=0; -a[i+1]+=a[i]/Ten; +a[i]%=Ten; -         } +  A     } at     returni+1; -  - } - intMain () - { -     intI,m,flag; inmemset (a,-1Nsizeof(int)); -scanf"%d",&m); toa[0]=1; +      for(i=2; i<=m;i++) -     { theflag=imitation (i); *     } $      for(i=flag;i>=0; i--)Panax Notoginseng     { -         if(a[i]>=0) theprintf"%d", A[i]); +     } Aprintf"\ n"); the     return 0; +}

1  2#include <iostream>3#include <iomanip>4 using namespacestd;5 //to store factorial within 200006 inta[15470];7 intMain ()8 {9     //freopen ("1.txt", "R", stdin);Ten     //freopen ("2.txt", "w", stdout); One     intN; ACin>>N; -a[1]=1; -a[0]=1; the     intUp ; -      for(intI=2; i<=n;++i) -     { -up=0; +          for(intj=1; j<=a[0];++J)//each phase multiply -         { +A[J] *=i; AA[J] + =Up ; atup=a[j]/100000; -A[J]%=100000; -         } -         if(up!=0) -         { -a[0]++; ina[a[0]]=Up ; -         } to     } +     if(a[0]==1) cout<<a[1]; -         Else the         { *cout<<a[a[0]]; $              for(inti=a[0]-1;i>0; i--)Panax Notoginseng             { -Cout<<setfill ('0') &LT;&LT;SETW (5) <<A[i]; the             } +         } A}

Nyoj 28 Large number factorial

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.