Ejemplo n.º 1
0
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 math
import prime
import functools
numerator = 1
denominator = 1
for n in range(1,9):
    for d in range(n+1,10):
        for x in range(math.ceil((10*n-d)/9),10):
            if d*(9*n+x) == 10*n*x and 10*n + x < 10*x + d:                
                print("From " + str(10*n+x) + "/" + str(10*x+d))
                print("we can cancel " + str(x))
                print("to get " + str(n) + "/" + str(d) + ".")
                print()
                numerator *= n
                denominator *= d

factored_numerator = prime.factor(numerator)
factored_denominator = prime.factor(denominator)
for f in factored_numerator:
    factored_denominator.remove(f)
print(functools.reduce(lambda x, y : x*y, factored_denominator))

                
                
Ejemplo n.º 2
0
"""
The first two consecutive numbers to have two distinct prime factors are:

14 = 2 × 7
15 = 3 × 5

The first three consecutive numbers to have three distinct prime factors are:

644 = 2² × 7 × 23
645 = 3 × 5 × 43
646 = 2 × 17 × 19.

Find the first four consecutive integers to have four distinct prime factors. What is the first of these numbers?
"""

from prime import factor

ci = 1
nf = 4
ns = 4
n = 2 * 3 * 5 * 7
while ci != ns:
    n += 1
    if len(factor(n)) == nf:
        ci += 1
    else:
        ci = 0

print n - nf + 1
Ejemplo n.º 3
0
def d(n):
    proper_divisors = find_divisors(prime.factor(n))
    proper_divisors.remove(n)
    return sum(proper_divisors)
Ejemplo n.º 4
0
"""
The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?
"""

import prime

N = 600851475143
factors = prime.factor(N)
print(factors[-1])