Example #1
0
def largestprimefactor(n):
    if type(n) is not int and type(n) is not long:
        raise TypeError
    allfactors = factors(n)
    # Now we have a list of factor pairs (non-prime)
    # Let's find which of these are prime numbers
    pfactors = []
    for factorpair in allfactors:
        if isprime(factorpair[0]):
            pfactors.append(factorpair[0])
        if isprime(factorpair[1]):
            pfactors.append(factorpair[1])
    # print(pfactors)
    return max(pfactors)
Example #2
0
def d(n):
    # Sum of proper divisors of n
    s = 0
    pairs = factors(n)
    for pair in pairs:
        if pair[0] == pair[1]:
            # count divisors only once
            s += pair[0]
        elif pair[0] == 1:
            # Don't add n
            s += pair[0]
        else:
            s += pair[0]
            s += pair[1]
    return s
Example #3
0
def primeFactors(n, conv=False):
    prime_factors = {}
    for pair in factors(n):
        for num in pair:
            if isprime(num):
                prime_factors[num] = 1
    prod = 1
    for prime_factor in prime_factors:
        prod = prod * prime_factor
    while prod != n:
        quotient = n / prod  # i.e. what we still need to represent with the prime factors
        for prime_factor in prime_factors:
            if quotient % prime_factor == 0:
                prod = prod * prime_factor
                prime_factors[prime_factor] += 1
    if conv is False:
        return prime_factors
    else:
        return primefactorconverter(prime_factors)
Example #4
0
     1: 1
     3: 1,3
     6: 1,2,3,6
    10: 1,2,5,10
    15: 1,3,5,15
    21: 1,3,7,21
    28: 1,2,4,7,14,28

We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?

"""

from lib import factors

triangle=1
last=2

f=factors()

while True:
	triangle=triangle+last
	last=last+1
	k=f.factor_count(triangle)
	if k>500:
		break
	
	
print(triangle)
Example #5
0
def method_max(N):
    return max(factors(N))
Example #6
0
def len_fac(n):
    return len(set(lib.factors(n)))
Example #7
0
File: 3.py Project: k-natt/public
def method_max(N):
	return max(factors(N))
Example #8
0
def smallest_divisible(min_, max_):
	facts = mset()
	for i in range(min_, max_+1):
		facts += mset(factors(i)) - facts

	return reduce(mul, facts.elements(), 1)