reserve d,i,j,k,m,n,p,q,x,k1,k2 for Nat,
  a,c,i1,i2,i3,i5 for Integer;

theorem Th37:
  for p being Nat holds p is prime & n,p are_coprime
  implies (n |^ (p -'1)) mod p = 1
proof
  let p be Nat;
  assume that
A1: p is prime and
A2: n,p are_coprime;
A3: p <> 0 by A1,INT_2:def 4;
A4: n <> 0
  proof
    assume n = 0;
    then n gcd p = p by NEWTON:52;
    then n gcd p > 1 by A1,INT_2:def 4;
    hence contradiction by A2,INT_2:def 3;
  end;
  then
A5: (n |^ (p -'1)) <> 0 by PREPOWER:5;
  (n |^ p) mod p = n mod p by A1,EULER_2:19;
  then
A6: (n |^ (p -' 1))*n mod p = n mod p by A3,A4,Th26;
  p > 1 by A1,INT_2:def 4;
  hence thesis by A2,A6,A5,EULER_2:12;
end;
