reserve i,i1,i2,i3,i4,i5,j,r,a,b,x,y for Integer,
  d,e,k,n for Nat,
  fp,fk for FinSequence of INT,
  f,f1,f2 for FinSequence of REAL,
  p for Prime;
reserve fr for FinSequence of REAL;
reserve fr,f for FinSequence of INT;
reserve b,m for Nat;

theorem Th21:
  p > 2 & a gcd p = 1 & not a is_quadratic_residue_mod p implies
  (a|^((p-'1) div 2) + 1) mod p = 0
proof
  assume that
A1: p > 2 and
A2: a gcd p = 1 and
A3: not a is_quadratic_residue_mod p;
A4: p-1<p by XREAL_1:146;
  a|^((p-'1) div 2) mod p = p-1 by A1,A2,A3,Th19;
  then a|^((p-'1) div 2) mod p = (p-1) mod p by A4,NAT_D:63;
  then a|^((p-'1) div 2),(p-1) are_congruent_mod p by NAT_D:64;
  then p divides -((a|^((p-'1) div 2)+1) - p) by INT_2:10;
  then p divides (p-(a|^((p-'1) div 2)+1));
  then p divides (a|^((p-'1) div 2)+1) by Th2;
  hence thesis by INT_1:62;
end;
