A simple prime-number bot, in python. WIP
mastodon
python
fediverse
bot
mathematics
prime-numbers

bailliePSW.py 712B

1234567891011121314151617181920212223242526272829303132
  1. from psimp import in_100, hund_div
  2. from lucas import LucasPrime, StrongLucasPrime
  3. from millerrabin import MillerRabin
  4. def BailliePSW(n):
  5. """Run Baillie-PSW probable prime test
  6. """
  7. if n < 2:
  8. return False
  9. if in_100(n):
  10. return True
  11. if hund_div(n) != 0:
  12. return False
  13. if MillerRabin(n, 2):
  14. return False
  15. return StrongLucasPrime(n)
  16. def BailliePSWWeak(n):
  17. """Run a weaker version of the Baillie-PSW probable prime test, using the
  18. weaker lucas test.
  19. """
  20. if n < 2:
  21. return False
  22. if in_100(n):
  23. return True
  24. if hund_div(n) != 0:
  25. return False
  26. if MillerRabin(n, 2):
  27. return False
  28. return LucasPrime(n)