Example #1
0
''' the idea is simple: factorize every number from 1 to 20, that is to
reduece every number to its basic form (a unique form expessed using only
prime numbers, due to the fact that every natural number has a unique form).
and then find the maximum power of each prime element.  

1*2*3*(2*2)*5*(2*3)*7*(2*2*2)*(3*3)*(2*5)*11*(2*2*3)*13*(2*7)*(3*5)*(2*2*2*2)*17*(2*3*3)*19*(2*2*5)

1*(2**4)*(3**2)*5*7*11*13*17*19
'''

from euler import uniprimefact, product

nums    = range(1, 20)

d   = {}
for i in nums:
    for (prime, power) in uniprimefact(i).items():
        if (prime in d and d[prime] < power) or (prime not in d):
            d[prime]    = power 

print product(prime**power for (prime, power) in d.items())
Example #2
0
''' the idea is simple: factorize every number from 1 to 20, that is to
reduece every number to its basic form (a unique form expessed using only
prime numbers, due to the fact that every natural number has a unique form).
and then find the maximum power of each prime element.  

1*2*3*(2*2)*5*(2*3)*7*(2*2*2)*(3*3)*(2*5)*11*(2*2*3)*13*(2*7)*(3*5)*(2*2*2*2)*17*(2*3*3)*19*(2*2*5)

1*(2**4)*(3**2)*5*7*11*13*17*19
'''

from euler import uniprimefact, product

nums = range(1, 20)

d = {}
for i in nums:
    for (prime, power) in uniprimefact(i).items():
        if (prime in d and d[prime] < power) or (prime not in d):
            d[prime] = power

print product(prime**power for (prime, power) in d.items())
Example #3
0
# for more information about this problem, check
# http://mathschallenge.net/index.php?section=faq&ref=number/number_of_divisors
#
# According to Fundamental Theorem of Arithmetic (or Unique Prime-Factorization 
# theorem) <http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic>,
# n can be uniquely represented by a^x * b^y * c^z, where a, b, c are primes
# let d(n) = the number of divisors of n
# then d(n) = (x+1) * (y+1) * (z+1)

from euler import uniprimefact, product
from itertools import count


def trinum(n):
    ''' Return the n-th triangle number '''
    return n*(n+1)/2

def trinumgen():
    ''' Generate the sequence of triangle numbers '''
    for n in count(1):
        yield trinum(n)

for trin in trinumgen():
    if product(each + 1 for each in uniprimefact(trin).values()) > 500:
        print trin
        break
Example #4
0
# for more information about this problem, check
# http://mathschallenge.net/index.php?section=faq&ref=number/number_of_divisors
#
# According to Fundamental Theorem of Arithmetic (or Unique Prime-Factorization
# theorem) <http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic>,
# n can be uniquely represented by a^x * b^y * c^z, where a, b, c are primes
# let d(n) = the number of divisors of n
# then d(n) = (x+1) * (y+1) * (z+1)

from euler import uniprimefact, product
from itertools import count


def trinum(n):
    ''' Return the n-th triangle number '''
    return n * (n + 1) / 2


def trinumgen():
    ''' Generate the sequence of triangle numbers '''
    for n in count(1):
        yield trinum(n)


for trin in trinumgen():
    if product(each + 1 for each in uniprimefact(trin).values()) > 500:
        print trin
        break