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 Th19:
  p>2 & a gcd p = 1 & not a is_quadratic_residue_mod p implies
  a|^((p-'1) div 2) mod p = p - 1
proof
  assume that
A1: p>2 and
A2: a gcd p = 1 and
A3: not a is_quadratic_residue_mod p;
  set l = a mod p;
  reconsider l as Element of NAT by INT_1:3,57;
A4: l mod p = a mod p by NAT_D:65;
  then
A5: l,a are_congruent_mod p by NAT_D:64;
  then l gcd p = 1 by A2,WSIERP_1:43;
  then l|^((p-'1) div 2) mod p = p - 1 by A1,A3,A5,Th11,Th18;
  hence thesis by A4,Th13;
end;
