|
43 | 43 | import math # Use sqrt, floor
|
44 | 44 | import functools # Use reduce (Python 2.5+ and 3.x)
|
45 | 45 |
|
| 46 | +def euler_criterion(a, p): |
| 47 | + """p is odd prime, a is positive integer. Euler's Criterion will check if a is QR mod p. If yes, returns True. If a is NR mod p, then False""" |
| 48 | + return a ** ((p - 1) / 2) % p == 1 |
| 49 | + |
46 | 50 | def gcd(a,b):
|
47 | 51 | """gcd(a,b) returns the greatest common divisor of the integers a and b."""
|
48 | 52 | a = abs(a); b = abs(b)
|
@@ -185,7 +189,7 @@ def TSRsqrtmod(a,grpord,p):
|
185 | 189 | # Now a*(g**powg) is in cyclic group of odd order non2 - can sqrt directly
|
186 | 190 | d = invmod(2,non2)
|
187 | 191 | tmp = pow(a*pow(g,gpow,p),d,p) # sqrt(a*(g**gpow))
|
188 |
| - return (tmp*inverse_mod(pow(g,gpow//2,p),p)) % p # sqrt(a*(g**gpow))//g**(gpow//2) |
| 192 | + return (tmp*inverse_mod(pow(g,gpow//2,p),p)) % p # sqrt(a*(g**gpow))//g**(gpow//2) |
189 | 193 |
|
190 | 194 | ################ Internally used functions #########################################
|
191 | 195 |
|
@@ -256,8 +260,8 @@ def invmod(b,n):
|
256 | 260 | return inverse_mod(b,n)
|
257 | 261 |
|
258 | 262 | def eulerphi(n):
|
259 |
| - """eulerphi(n) - Compute Euler's Phi function of n - the number of integers strictly less than n which are coprime to n. |
260 |
| - (Renamed euler_phi(n) in ver 0.7)""" |
| 263 | + """eulerphi(n) - Compute Euler's Phi function of n - the number of integers strictly less than n which are coprime to n. |
| 264 | + (Renamed euler_phi(n) in ver 0.7)""" |
261 | 265 | return euler_phi(n)
|
262 | 266 |
|
263 | 267 | def carmichaellambda(n):
|
|
0 commit comments