I didn’t know this definition. It means that 1 and 2 are highly composite numbers, despite neither being composite…2 is of course prime and 1 is a unit (since it needs to be ignored for unique factoring). I guess fair enough, it feels weird to specifically exclude them, but it’s weird to have them too.
You need some of those pants with the expandable leg holes. It removes the frustration of having to start over when you accidentally start with the shoes.
Any of yall wanna earn 25 grand for your kid, or maybe just tired of jokes about shoes and pants? Here’s my solution:
import math
# find all antiprimes less than <limit>
def find_antiprimes(limit):
# list of primes
primes = []
# dictionary of composite numbers and their factors:
# {n: {2: <power of two>, 3: <power of three>, etc}, etc}
composites = {}
factor_count = 0
antiprimes = {}
for n in range (2, limit):
# factorize n
if len(primes) == 0:
primes.append(n)
composites[n] = {n: 1}
else:
for p in primes:
# if no divisors found by p > sqrt(n), n is a prime
if p > math.sqrt(n):
primes.append(n)
composites[n] = {n: 1}
break
if n % p == 0:
# n == p * d
composites[n] = {}
d = int(n/p)
# copy the factor dictionary
for c in composites[d]:
composites[n][c] = composites[d][c]
# update the factor count for p
if composites[n].get(p) == None:
composites[n][p] = 1
else:
composites[n][p] += 1
break
# count the factors
factors = 1
for c in composites[n]:
factors *= (composites[n][c] + 1)
if factors > factor_count:
# antiprime is found
factor_count = factors
antiprimes[n] = factors
print ("antiprime " + str(n) + " has " + str(factors) + " factors.")