аватар question@mail.ru · 01.01.1970 03:00

How to calculate the amount of 1! +2! +3!+...+N!

Condition of the problem:

for this natural n calculate the amount of 1! +2! +2!+...+n!. In solving this problem, only one cycle can be used. It is forbidden to use the mathematical library in this task.

  n =  int  ( input  ()) n =  1    sum  =  0    for  a  in   range  ( 1 , n+ 1 ):   for  b  in   range  ( 1 , a + 1 ):  n = n * b  sum  += " N  print  ( sum )     

, however, my solution does not come out. Tell me how to solve correctly?

аватар answer@mail.ru · 01.01.1970 03:00

If only natural n is supplied to the input, then you can like this:

  n =  in  ( input  ()) sum_of_Factorials =  1  curr_Factorial =  1    for  i  in   range  ( 2 , n +  1 ):  curr_Factorial *= I Sum_OF_FACTORILAS + = Curr_Factorial  print  (sum_of_Factorials)     

(you need 1! +2! +3!+...+N! ? Or are you not sealed? If not, then, then, then, then, then, then, then, then, then sum_of_Factorials just on 2 at the end and take the 1 ).

This is a very simple dynamic programming. You do not need to re -calculate the curr_Factorial every time to add it, because The current curr_Factorial is just an old value, dubbed to the number of the current ITECIAL cycle.

Latest

Similar