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

lucas.py 540B

123456789101112131415161718192021222324
  1. # Finding lucas pseudoprimes
  2. from math import sqrt
  3. def isqrt(n):
  4. """ Find the integer square root of n via newton's method, code via
  5. stackoverflow:
  6. (https://stackoverflow.com/questions/15390807/integer-square-root-in-python)
  7. """
  8. x = n
  9. y = (x + 1) // 2
  10. while y < x:
  11. x = y
  12. y = (x + n // x) // 2
  13. return x
  14. def hasIntSQRT(n):
  15. """Detect whether the square root of n is an integer,
  16. i.e. whether the isqrt(n) is the true square root.
  17. """
  18. isq = isqrt(n)
  19. return isq * isq == n