Add basic tests of semi-primality and k-almost primality

This commit is contained in:
Emile Clark-Boman 2025-07-01 18:04:00 +10:00
parent 3a407b6456
commit d403da53db
3 changed files with 24 additions and 0 deletions

View file

@ -0,0 +1,5 @@
def factorial(n: int) -> int:
if n == 0: return 1
return n * factorial(n-1)
def

View file

@ -0,0 +1 @@

View file

@ -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
''' '''