type Result = ℕ[N^M];
type nat = ℕ[K];
+// Elementary division
+pred divides(m:nat,n:nat) ⇔ ∃p:nat. m*p = n;
+
+// Quadratic residue
+// a ∈ ℤ/pℤ is a quadratic residue ⇔
+// x^2 - a has a zero in ℤ/pℤ
+// defined for p prime > 2 only
+proc isquadraticresidue(a:nat,p:nat): Bool
+{
+ var res:Bool = false;
+ var i:nat = 0;
+
+ while i < p ∧ res = false do
+ {
+ if (i^2-a)%p = 0 then
+ res = true;
+ i = i+1;
+ }
+
+ return res;
+}
+
+// Legendre Symbol (a/p)
+// == 0 divides(p,a)
+// == 1 a is quadratic residue modulo p
+// == -1 a is NOT quadratic residue modulo p
+
+
////////////////////////////////////////////////////////////////////
// Algorithm: Calcluate Integer Root of a
// See http://www.inf.fh-flensburg.de/lang/se/veri/aufg/wurzel.htm
+