def distinct_prime_factor_count(n): f = factors(n) - set([1, n]) prime_factors = set([]) for p in f: if isprime(p): prime_factors.add(p) return len(prime_factors)
def main(limit: int): """Return the triangle number with factors over the limit. :return: Triangle number with over the `limit` divisors. """ for triangle_number in triangle_number_generator(): if len(factors(triangle_number)) > limit: return triangle_number else: continue
def is_abundant(n): fs = factors(n) fs.remove(n) s = 0 for f in fs: s += f if s > n: return True else: return False
#!/usr/bin/python from common import factors #set the total to 0 total = 0 #go through all numbers (1, 10000] for a in range(1, 10000): b = sum(factors(a)) #if d(a) == d(b) and a != b add to total if a != b and a == sum(factors(b)): total += a #print the total print total
from common import factors N = 999 * 999 def palindrome(num): num = str(num) n = len(num) // 2 if num[0:n][::-1] == num[n if n % 2 != 0 else n + 1 : ]: return True else: return False #Check to see if there is a factor of length 3 that matches with another length 3 factor. def check_factors(factors, n) : factors = filter(lambda x: len(str(x)) == 3, factors) for i in factors: if(len(str(n/i)) == 3): print i, n/i return True for i in xrange(N, 100 * 100, -1): if palindrome(i) and check_factors(factors(i), i): print 'Biggest Palindrome is ', i break;
if i > value/2: return False tmp = abundantNumbers.index(value-i) return True except: continue return False #largest number that can't be written as sum of 2 abundeant numbers maxNumber = 28123 #list of abundunt numbers abundantNumbers = [] #sum of numbers that cant be added up by 2 abundant numbers total = 0 #go through all numbers below max for i in range(1, maxNumber+1): #get the sum of the factors and append to abundant if it is if sum(factors(i)) > i: abundantNumbers.append(i) #if it is now abundant add to total if not isAbundant(i): total += i print total
# Problem 3 # 02 November 2001 # The prime factors of 13195 are 5, 7, 13 and 29. # What is the largest prime factor of the number 600851475143 ? from common import factors print(list(factors(600851475143))[-1])
#!/usr/bin/env python from common import factors def triangle_number(n): return sum(xrange(n+1)) for n in xrange(2, 100000): tn = triangle_number(n) ln = len(factors(tn)) #print n, tn, ln if ln > 100: print "Over 100 factors ", n, tn, ln if ln > 500: print "Over 500 factors ", n, tn, ln break
def prime_factors(n, sieve): f = factors(n) f.remove(1) f.remove(n) return [i for i in f if sieve[i]]