Is q a quadratic residue of n?
Mathematica, 25 bytes
AtomQ@PowerMod[#,1/2,#2]&
Mathematica, being Mathematica, naturally has a builtin for calculating modulo nth roots, via PowerMod
. If a solution exists the smallest feasible solution is returned, otherwise the original expression (plus a message).
To get an actual truthy/falsy output we pass the result to AtomQ
, which checks whether an expression can be broken down. Integers are atomic, returning True
, whilst the non-atomic PowerMod[q,1/2,n]
returns False
Thanks to @MartinBüttner for golf tips and function hunting with me.
Par, 11 9 bytes
✶X[²x%)↔,
Each character uses just one byte; see here.
Explanation
✶ ## Read two numbers
X ## Assign second to x
[ ## Map
² ## Square
x% ## Mod x
) ##
↔ ## Swap
, ## Count
Removed two bytes thanks to Jakube.
LabVIEW, 16 15 Equivalent bytes
Counted according to my meta post.