The sum of P1009 factorial

Source: Internet
Author: User

The sum of P1009 factorial
    • Topic provider Rokua Onlinejudge
    • Tag number theory (mathematics-related) high-precision 1998Noip Increase group Noip popularization Group
    • Difficulty Popularization-
    • Pass/Submit 1139/3791

Submit a discussion of the problem record

Title Description

Calculate the s=1! with high precision +2! +3! +...+n! (N≤50)

Which "! "denotes factorial, for example: 5! =5*4*3*2*1.

Input output Format input format:

A positive integer n.

Output format:

A positive integer s that represents the result of the calculation.

Input and Output Sample input example # #:
3
Sample # # of output:
9
#include <iostream>#include<cstring>using namespacestd;inta[100000],n,i,j,x[100000],y[100000];voidAdd ()//Handling Rounding{memset (x,0,sizeof(x)); x[0]=max (y[0],a[0]);  for(i=1; i<=x[0];i++) {x[i]+=y[i]+a[i],x[i+1]=x[i]/Ten, x[i]%=Ten;}  while(x[x[0]+1]>0) {x[x[0]+2]=x[x[0]+1]/Ten, x[x[0]+1]%=Ten, x[0]++;} y[0]=x[0];  for(i=1; i<=x[0];i++) {y[i]=x[i];}}intMain () {CIN>>N; a[0]=1, a[1]=1, y[0]=1, y[1]=0;  for(j=1; j<=n;j++) {memset (x,0,sizeof(x));//Clear Order Multiplier Groupx[0]=a[0];  for(i=1; i<=a[0];i++) {x[i]+=a[i]*j,x[i+1]=x[i]/Ten, x[i]%=Ten;}//analog factorial         while(x[x[0]+1]>0) {x[x[0]+2]=x[x[0]+1]/Ten, x[x[0]+1]%=Ten, x[0]++;}//plus factorial         for(i=1; i<=x[0];i++) {a[i]=x[i];} a[0]=x[0];    Add (); }     for(i=y[0];i>=1; i--) {cout<<y[i];}//Reverse storage will be reversed output    return 0;}

The sum of P1009 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.