In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to solve the pyramid number summation problem with Python/R language respectively". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
1. First N factorial summation
Factorial is a mathematical term invented by Christian Kramp (1760 - 1826) in 1808.
n!= 1∗2∗3∗...∗(n−1)∗n
Or you can define it recursively:
The sum of the factorial of its first N terms is sum(1!+ 2!+ 3!+...+ n!),With the above theoretical basis, let's look at the diagram together to strengthen our understanding!
1.1 graphical problem
As shown in the figure, if you want to output each value, you can embed the idea of a loop, and multiply the previous value every time!
1.2 algorithm flow
Here we can see that we need to manually control how many terms we need to count first. Inside the loop, this is the accumulation and assignment of factorial numbers.
1.3 code implementation
1.3.1 Python code implementation
n = int(input("n = "))s = 0t = 1for i in range(1,n+1): t*=i s+=tprint ("sum of previous {} factorial is: {}" .format(n,s))
1.3.2 R Language Code Implementation
factorial
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.