Added section for number theoretic functions
This commit is contained in:
parent
588c2acf7c
commit
9e2ea469db
2 changed files with 22 additions and 0 deletions
16
imp/math/numbers.py
Normal file
16
imp/math/numbers.py
Normal 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())
|
||||
|
|
@ -1,2 +1,8 @@
|
|||
from itertools import chain, combinations
|
||||
|
||||
def digits(n: int) -> int:
|
||||
return len(str(n))
|
||||
|
||||
def powerset(iterable):
|
||||
s = list(iterable)
|
||||
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue