The and (Python) of the factorial from 1 to n

Source: Internet
Author: User

Today in Baidu stroll some of the platform of CTF, accidentally found a programming problem, then, I just learned the Python knowledge to solve the problem

The description of the topic is this:

Calculates the 1!+2!+3!+...+6666! after five bits.

This calculation is very large, I still use the traditional method, let the computer calculate it

Here is the code:

1 #-*-coding:utf-8-*-2 #Calculate 1!+2!+3!+......+n!3 ImportSYS4 5 deffact (x):6result = 17      forIinchXrange (2,x+1):8Result *=I9     returnresultTen  One defEnd_result (n): ARESULT1 =0 -      forIinchXrange (1,n+1): -RESULT1 + =fact (i) the     returnRESULT1 -  - if __name__=='__main__': -num = Int (sys.argv[1]) +     PrintEnd_result (num)

Have to say that Python is powerful, so long data can be listed

The and (Python) of the factorial from 1 to n

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.