We are given the prime
Using Legendre Symbol and Euler's criterion, a number
But when the prime is of the form
Multiply both sides by
Denote the quadratic residue of
Combining the two equations above, we have:
Taking the square root of both sides:
Hence, the positive quadratic residue of
Otherwise, for the general case, we can use algorithms like Tonelli-Shanks and Cipolla's algorithm.
With this, we can easily solve the challenge by appending the following code to output.txt
:
xxxxxxxxxx
print("Prime in form of 4k + 3:", p % 4 == 3)
for i in ints:
if pow(i, (p - 1) // 2, p) == 1:
print(pow(i, (p + 1) // 4, p))