I have used Legendre's symbol, and get correct output for all the input of this thread.
Maybe I haven't computed right Legendre's symbol.
If someone can explain me a bit how have computed this to solve the problem, I will be happy

By other hand I have here some test cases, if someone can say if the output is correct I will be happy too

I have used Legendre's symbol, and get correct output for all the input of this thread.
Maybe I haven't computed right Legendre's symbol.
If someone can explain me a bit how have computed this to solve the problem, I will be happy

By other hand I have here some test cases, if someone can say if the output is correct I will be happy too

I had a small bug at my algorithm. But one question, I have obtained a time of 0:00.535, and most of solvers have obtained a time about 0:00.030 or smaller, I would like know the method used. I used a method that is about Legendre's symbol and law of quadratic reciprocity, in this method I must break down a number in his prime numbers, and make transformations to obtain trivial cases that I can solve directly.