diff --git a/imp/math/numbers/functions.py b/imp/math/numbers/functions.py new file mode 100644 index 0000000..6cafa7f --- /dev/null +++ b/imp/math/numbers/functions.py @@ -0,0 +1,5 @@ +def factorial(n: int) -> int: + if n == 0: return 1 + return n * factorial(n-1) + +def diff --git a/imp/math/numbers/kinds.py b/imp/math/numbers/kinds.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/imp/math/numbers/kinds.py @@ -0,0 +1 @@ + diff --git a/imp/math/primes.py b/imp/math/primes.py index 513f61e..eaeebcb 100644 --- a/imp/math/primes.py +++ b/imp/math/primes.py @@ -1,5 +1,23 @@ from math import gcd +from imp.math.numbers import bigomega +def coprime(n: int, m: int) -> bool: + return gcd(n, m) == 1 + +def almostprime(n: int, k: int) -> bool: + ''' + A natural n is "k-almost prime" if it has exactly + k prime factors (including multiplicity). + ''' + return (bigomega(n) == k) + +def semiprime(n: int) -> bool: + ''' + A semiprime number is one that is 2-almost prime. + Ref: https://en.wikipedia.org/wiki/Semiprime + ''' + return almostprime(n, 2) + ''' Euler's Totient (Phi) Function '''