def distinct_pf_seq_start(p):
    n, i = 2, 0
    while i < p:
        n += 1
        if len(prime_factors(n)) >= p:
            i += 1
        else:
            i = 0
    return n - p + 1
Beispiel #2
0
def doProb3():
    print max(prime_factors(600851475143))
Beispiel #3
0
"""
Project Euler Problem 33
========================

The fraction 49/98 is a curious fraction, as an inexperienced
mathematician in attempting to simplify it may incorrectly believe that
49/98 = 4/8, which is correct, is obtained by cancelling the 9s.

We shall consider fractions like, 30/50 = 3/5, to be trivial examples.

There are exactly four non-trivial examples of this type of fraction, less
than one in value, and containing two digits in the numerator and
denominator.

If the product of these four fractions is given in its lowest common
terms, find the value of the denominator.
"""

import euler_utils as utils

numerator = 1
denominator = 1

for i in range(10,99):
    for j in range(i+1, 100):
        if str(i)[1] == str(j)[0] and str(j)[1] != '0' and float(i)/float(j) == float(str(i)[0])/float(str(j)[1]):
            numerator *= i
            denominator *= j

print utils.prod(utils.remove_from_list(utils.prime_factors(denominator), utils.prime_factors(numerator)))
Beispiel #4
0
                    {20,48,52}, {24,45,51}, {30,40,50}

For which value of p < 1000, is the number of solutions maximised?
"""



import euler_utils as utils

perimeter_solutions = [0 for x in range(1001)];

for p in range(4, 501):  #I could have written a simpler solution
    for m in range(p,1, -1):
        for n in range(1,m):
            if m*(m+n) > p:
                break
            if not ((m+n)%2 == 1) or not (len(set(utils.prime_factors(m)).intersection(set(utils.prime_factors(n)))) == 0):
                continue
            a = 2*m*n
            b = (m**2)-(n**2)
            c = (m**2)+(n**2)
            if (a**2 + b**2 ) == (c**2) and (a+b+c) == 2*p:
               perimeter = 2*p
               d = perimeter
               while d <= 1000:
                   perimeter_solutions[d] += 1
                   d += perimeter

print perimeter_solutions.index(max(perimeter_solutions))