Add basic tests of semi-primality and k-almost primality
This commit is contained in:
parent
3a407b6456
commit
d403da53db
3 changed files with 24 additions and 0 deletions
5
imp/math/numbers/functions.py
Normal file
5
imp/math/numbers/functions.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
def factorial(n: int) -> int:
|
||||||
|
if n == 0: return 1
|
||||||
|
return n * factorial(n-1)
|
||||||
|
|
||||||
|
def
|
||||||
1
imp/math/numbers/kinds.py
Normal file
1
imp/math/numbers/kinds.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -1,5 +1,23 @@
|
||||||
from math import gcd
|
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
|
Euler's Totient (Phi) Function
|
||||||
'''
|
'''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue