Euler Project question in Python

Source: Internet
Author: User

# This Python file uses the following encoding:utf-8
# Consider all integers combinations of ab for 2≤a≤5 and 2≤b≤5:

# 22=4, 23=8, 24=16, 25=32
# 32=9, 33=27, 34=81, 35=243
# 42=16, 43=64, 44=256, 45=1024
# 52=25, 53=125, 54=625, 55=3125
# If They is then placed in numerical order, with any repeats removed, we get the following sequence of distinct terms :

# 4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125

# How many distinct terms is in the sequence generated by AB for 2≤a≤100 and 2≤b≤100?

Import time
Start = Time.time ()
L = []
For I in range (2, 101):
For j in range (2, 101):
If I**j not in L:
L.append (I**J)
Print "%s distinct powers is found in%s seconds"% (Len (l), Time.time ()-start)

# 9183 distinct powers WasFound in 1.46399998665 seconds

Euler Project question in Python

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.