123456789101112131415161718192021222324 |
- # Finding lucas pseudoprimes
- from math import sqrt
-
- def isqrt(n):
- """ Find the integer square root of n via newton's method, code via
- stackoverflow:
-
- (https://stackoverflow.com/questions/15390807/integer-square-root-in-python)
- """
- x = n
- y = (x + 1) // 2
- while y < x:
- x = y
- y = (x + n // x) // 2
- return x
-
- def hasIntSQRT(n):
- """Detect whether the square root of n is an integer,
- i.e. whether the isqrt(n) is the true square root.
- """
- isq = isqrt(n)
- return isq * isq == n
-
|