Added section for number theoretic functions

This commit is contained in:
Emile Clark-Boman 2025-07-01 15:33:24 +10:00
parent 588c2acf7c
commit 9e2ea469db
2 changed files with 22 additions and 0 deletions

16
imp/math/numbers.py Normal file
View file

@ -0,0 +1,16 @@
from imp.math.primefac import factors
def divisors(n: int) -> int:
'''
Returns the proper divisors of an integer n.
Also called the "aliquot parts" of n.
'''
pf = factors(n)
for (prime, multiplicity) in pf:
def aliquots(n: int) -> int:
return proper_divisors(n)
def amicable(n: int) -> int:
sum(proper_divisors())

View file

@ -1,2 +1,8 @@
from itertools import chain, combinations
def digits(n: int) -> int: def digits(n: int) -> int:
return len(str(n)) return len(str(n))
def powerset(iterable):
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))