The sum of factorial

Source: Internet
Author: User

The sum of factorial

"Title description" calculates the s=1! with high precision +2! +3! +...+n! (N≤50)
Which "! "denotes factorial, for example: 5! =5*4*3*2*1.

"Input format" a positive integer n.
"Output format" a positive integer s that represents the result of the calculation.

Train of thought: stripping by heightening the essence Plus

 ProgramAA;varN,l,ls,i:longint; A:Array[1.. +] ofLongint; S:Array[1.. +] ofThe longint;//s array is the next number to be added, which is the change. procedureJC (I:longint);//This process is used to find the S arrayvarJ:longint;begin    ifI=1  Then    beginL:=1; LS:=1; S[LS]:=1;    Exit End; ifI>1  Then    begin         forj:=1  toLs Dos[j]:=s[j]*i;//think about doing this for Mao. forj:=1  toLs Do            ifs[j]>=Ten  Then            beginInc (S[j+1],S[J]Div Ten); S[J]:=S[J]MoD Ten; End; ifs[ls+1]<>0  ThenInc (LS);  while s[ls]>=10  Do        beginInc (LS); Inc (S[ls],s[ls-1]Div Ten); S[ls-1]:=s[ls-1]MoD Ten; End; ifLs>=l Thenl:=ls; End;End;procedureWork ;varI,j,k:longint;begin     fori:=1  toNThe number of do//currently to be added is the factorial of I.     beginJC (i); forj:=1  toL DoInc (A[J],S[J]);//A few steps to add factorial to a forj:=1  toL Do            ifa[j]>=Ten  Then            beginInc (A[j+1],A[J]Div Ten); A[J]:=A[J]MoD Ten; End; ifa[l+1]<>0  ThenInc (L);  whilea[l]>=Ten  Do        beginInc (L); Inc (A[l],a[l-1]Div Ten); A[l-1]:=a[l-1]MoD Ten; End; End;End;beginREADLN (n);    Work  forI:=lDownto 1  Dowrite (a[i]);End.

A little reflection: At the beginning of the 215, because the red Word part of the error, written a array of ...

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