reserve a,b,k,m,n,s for Nat;
reserve c,c1,c2,c3 for Complex;
reserve i,j,z for Integer;
reserve p for Prime;
reserve x for object;

theorem Th18:
  for p being Prime, m,n st p mod 4 = 3
    holds
    divisors(p|^n,4,1)\/divisors(p|^n,4,3) =
      { k where k is Nat: k divides p|^n } &
    (n = 2*m implies
      card divisors(p|^n,4,1) = m+1 & card divisors(p|^n,4,3) = m) &
    (n = 2*m+1 implies
      card divisors(p|^n,4,1) = m+1 & card divisors(p|^n,4,3) = m+1)
  proof
    let p be Prime, m,n such that
A1: p mod 4 = 3;
    defpred P[Nat] means for m
    holds
    divisors(p|^$1,4,1)\/divisors(p|^$1,4,3) =
          { k where k is Nat: k divides p|^$1 } &
       ($1 = 2*m implies
          card divisors(p|^$1,4,1) = m+1 & card divisors(p|^$1,4,3) = m) &
       ($1 = 2*m+1 implies
          card divisors(p|^$1,4,1) = m+1 & card divisors(p|^$1,4,3) = m+1);
A2:P[0]
   proof
     let m be Nat;
     set X1 = divisors(p|^0,4,1),X3 = divisors(p|^0,4,3);
     set Y={ k where k is Nat: k divides p|^0 };
A3:  p|^0 = 1 by NEWTON:4;
     1 mod 4 = 1 by PEPIN:5;
     then
A4:  1 in X1 & 1 in Y by A3;
     X1 c= {1}
     proof
       let x be object;
       assume x in X1;
       then consider k be Nat such that
       A5:
       k=x & k mod 4 = 1 & k divides p|^0;
       k = 1 or k=-1 by A5,A3,INT_2:13;
       hence thesis by A5,TARSKI:def 1;
     end;
     then
A6:  X1={1} by A4,ZFMISC_1:33;
A7:  Y c= {1}
     proof
       let x be object;
       assume x in Y;
       then consider k be Nat such that
A8:    k=x & k divides p|^0;
       k = 1 or k=-1 by A8,A3,INT_2:13;
       hence thesis by A8,TARSKI:def 1;
     end;
     X3 = {}
     proof
       assume X3<>{};
       then consider x be object such that
A9:    x in X3 by XBOOLE_0:def 1;
       consider k be Nat such that
A10:   k=x & k mod 4 = 3 & k divides p|^0 by A9;
       k = 1 or k=-1 by A10,A3,INT_2:13;
       hence thesis by A10,PEPIN:5;
     end;
     hence thesis by CARD_1:30,A7,A4,ZFMISC_1:33,A6;
   end;
A11: for i being Nat holds P[i] implies P[i+1]
   proof
     let i be Nat;
     assume
A12: P[i];
     set i1=i+1;
     let m;
     set X1 = divisors(p|^i1,4,1),X3 = divisors(p|^i1,4,3);
     set X= { k where k is Nat: k divides p|^i1 },
     Y= { k where k is Nat: k divides p|^i },
     Y1 = divisors(p|^i,4,1),Y3 = divisors(p|^i,4,3);
A13: X1 c= X
     proof
       let x be object;
       assume x in X1;
       then ex k be Nat st x=k & k mod 4 = 1 & k divides p|^i1;
       hence thesis;
     end;
     X3 c= X
     proof
       let x be object;
       assume x in X3;
       then ex k be Nat st x=k & k mod 4 = 3 & k divides p|^i1 ;
       hence thesis;
     end;
     then
A14: X1 \/ X3 c= X by A13,XBOOLE_1:8;
     X c= X1\/X3
     proof
       let x be object;
       assume x in X;
       then consider k be Nat such that
A15:   x=k & k divides p|^i1;
       consider m be Nat such that
A16:   k = p|^m by A15,NEWTON03:36;
       per cases;
       suppose m is odd;
         then consider k1 be Nat such that
A17:     m=2*k1+1 by ABIAN:9;
         (p|^m) mod 4 = 3 by A17,A1,Th11;
         then k in X3 by A15,A16;
         hence thesis by A15,XBOOLE_0:def 3;
       end;
       suppose m is even;
         then consider k1 be Nat such that
A18:     m=2*k1;
         (p|^m) mod 4 = 1 by A18,A1,Th11;
         then k in X1 by A15,A16;
         hence thesis by A15,XBOOLE_0:def 3;
       end;
     end;
     hence X = X1 \/ X3 by A14,XBOOLE_0:def 10;
A19: p*p|^i= p|^i1 by NEWTON:6;
     thus i1 = 2*m implies card X1 = m+1 & card X3 = m
     proof
       assume
A20:   i1=2*m;
       then m <>0;
       then reconsider m1=m-1 as Nat;
       i = 2*m1+1 & Y=Y by A20;
       then
A21:   card Y1 = m1+1 & card Y3 = m1+1 by A12;
       reconsider Y as finite set by A12;
       Y \/ {p|^i1} = X by Lm5;
       then
A22:   not p|^i1 in Y by Lm5;
       p|^i1 mod 4 = 1 by A20,A1,Th11;
       then
A23:   p|^i1 in X1;
       Y1 c= X1
       proof
         let x be object;
         assume x in Y1;
         then consider k be Nat such that
A24:     x=k & k mod 4 = 1 & k divides p|^i;
         k divides p|^i1 by A24,A19,INT_2:2;
         hence thesis by A24;
       end;
       then
A25:   {p|^i1} \/ Y1 c= X1 by A23,ZFMISC_1:137;
       X1 c= {p|^i1} \/ Y1
       proof
         let x be object;
         assume x in X1;
         then consider k be Nat such that
A26:     x=k & k mod 4 = 1 & k divides p|^i1;
         consider t be Element of NAT such that
A27:     k = p|^t & t <= i1 by A26,PEPIN:34;
         assume not x in {p|^i1} \/ Y1;
         then
A28:     x <> p|^i1 & not x in Y1 by ZFMISC_1:136;
         then t < i1 by A26,A27,XXREAL_0:1;
         then t <= i by NAT_1:13;
         then k divides p|^i by A27,NEWTON:89;
         hence thesis by A26,A28;
       end;
       then
A29:   {p|^i1} \/ Y1 = X1 by A25,XBOOLE_0:def 10;
       not p|^i1 in Y1 by XBOOLE_0:def 3,A12,A22;
       hence card X1 = m+1 by A21,A29,CARD_2:41;
A30:   Y3 c= X3
       proof
         let x be object;
         assume x in Y3;
         then consider k be Nat such that
A31:     x=k & k mod 4 = 3 & k divides p|^i;
         k divides p|^i1 by A31,A19,INT_2:2;
         hence thesis by A31;
       end;
       X3 c= Y3
       proof
         let x be object;
         assume x in X3;
         then consider k be Nat such that
A32:     x=k & k mod 4 = 3 & k divides p|^i1;
         consider t be Element of NAT such that
A33:     k = p|^t & t <= i1 by A32,PEPIN:34;
         t <> i1 by A20,A32,A33,A1,Th11;
         then t < i1 by A33,XXREAL_0:1;
         then t <= i by NAT_1:13;
         then k divides p|^i by A33,NEWTON:89;
         hence thesis by A32;
       end;
       hence thesis by A21,A30,XBOOLE_0:def 10;
     end;
     assume
A34: i1=2*m+1;
     then
A35: card Y1 = m+1 & card Y3 = m by A12;
     reconsider Y as finite set by A12;
     Y \/ {p|^i1} = X by Lm5;
     then
A36: not p|^i1 in Y by Lm5;
     p|^i1 mod 4 = 3 by A34,A1,Th11;
     then
A37: p|^i1 in X3;
     Y3 c= X3
     proof
       let x be object;
       assume x in Y3;
       then consider k be Nat such that
A38:   x=k & k mod 4 = 3 & k divides p|^i;
       k divides p|^i1 by A38,A19,INT_2:2;
       hence thesis by A38;
     end;
     then
A39: {p|^i1} \/ Y3 c= X3 by A37,ZFMISC_1:137;
     X3 c= {p|^i1} \/ Y3
     proof
       let x be object;
       assume x in X3;
       then consider k be Nat such that
A40:   x=k & k mod 4 = 3 & k divides p|^i1;
       consider t be Element of NAT such that
A41:   k = p|^t & t <= i1 by A40,PEPIN:34;
       assume not x in {p|^i1} \/ Y3;
       then
A42:   x <> p|^i1 & not x in Y3 by ZFMISC_1:136;
       then t < i1 by A40,A41,XXREAL_0:1;
       then t <= i by NAT_1:13;
       then k divides p|^i by A41,NEWTON:89;
       hence thesis by A40,A42;
     end;
     then
A43: {p|^i1} \/ Y3 = X3 by A39,XBOOLE_0:def 10;
A44: not p|^i1 in Y3 by XBOOLE_0:def 3,A12,A36;
A45: Y1 c= X1
     proof
       let x be object;
       assume x in Y1;
       then consider k be Nat such that
A46:   x=k & k mod 4 = 1 & k divides p|^i;
       k divides p|^i1 by A46,A19,INT_2:2;
       hence thesis by A46;
     end;
     X1 c= Y1
     proof
       let x be object;
       assume x in X1;
       then consider k be Nat such that
A47:   x=k & k mod 4 = 1 & k divides p|^i1;
       consider t be Element of NAT such that
A48:   k = p|^t & t <= i1 by A47,PEPIN:34;
       t <> i1 by A34,A47,A48,A1,Th11;
       then t < i1 by A48,XXREAL_0:1;
       then t <= i by NAT_1:13;
       then k divides p|^i by A48,NEWTON:89;
       hence thesis by A47;
     end;
     hence thesis by A35,A45,A44,A43,CARD_2:41,XBOOLE_0:def 10;
   end;
   for i being Nat holds P[i] from NAT_1:sch 2(A2,A11);
   hence thesis;
 end;
