def is_reduced_proper_fraction(num, denom): common_factors = set(factors(num)) & \ set(factors(denom)) if len(common_factors) == 1: return True else: return False
def isamicable(n): pair = [] nfac = factors(n) nfac.pop() # Remove the number itself dn = sum(nfac) dnfac = factors(dn) dnfac.pop() dnp = sum(dnfac) # print n, dn, dnp if (dnp == n): pair.append(n) pair.append(dn) return pair
def isabundant(num): isab = 0 fac = factors(num) fac.pop() # remove the number itself from the list if (sum(fac) > num): isab = 1 return isab
from eulermath import factors if __name__ == "__main__": # Test case, 7th triangle number is 28 and is the first to have > 5 factors # fmax = 5 fmax = 500 i = 1 # print "i tri" while True: # What is the corresponding triangle number tri = sum(range(1, i)) nfac = len(factors(tri)) # print i, tri, factors(tri) if (nfac > fmax): break i += 1 print "The first triangle number to have over", fmax, "factors is:", tri