reserve a,b,d,n,k,i,j,x,s for Nat;

theorem Th36:
  for n being Nat, p being Prime st p <= n & p|^2 divides n! holds 2*p <= n
proof
  let n be Nat, p be Prime such that
A1: p <= n & p|^2 divides n! & 2*p > n;
  p|^(1+1) = p*(p|^1) by NEWTON:6;
  then consider o be Nat such that
A2: p*p*o = n! by A1,NAT_D:def 3;
  set I=idseq n;
  for r being Real st r in rng I holds 0 < r
  proof
    let r be Real;
    assume r in rng I;
    then consider x be object such that
A3:   x in dom idseq n & I.x = r by FUNCT_1:def 3;
    reconsider x as Nat by A3;
    I = id Seg n by FINSEQ_2:def 1;
    then r =x by A3,FINSEQ_2:49;
    hence thesis by A3,FINSEQ_3:25;
  end;
  then
A4: I is positive-yielding by PARTFUN3:def 1;
A5: 1 < p <= len I by A1,INT_2:def 4;
  then
A6: I =(I| (p-'1))^<*I.p*>^(I /^ p) by FINSEQ_5:84;
  then
A7:Product I = Product ((I| (p-'1))^<*I.p*>) * Product (I /^ p)
  by RVSUM_1:97
  .= Product (I | (p-'1))* (I.p) * Product (I /^ p) by RVSUM_1:96
  .= Product (I | (p-'1)) * Product (I /^ p) * (I.p)
  .= Product ((I | (p-'1)) ^ (I /^ p)) * (I.p) by RVSUM_1:97;
  p in Seg n by A5;
  then
A8: I.p = p by FINSEQ_2:49;
A9:(I| (p-'1))^<*I.p*> is positive-yielding &
   (I /^ p) is positive-yielding by A4,A6,NUMBER08:37;
  then (I| (p-'1)) is positive-yielding by NUMBER08:37;
  then
A10:(I| (p-'1))^(I /^ p) is positive-yielding by A9;
  Product I = n! by NEWTON:def 2;
  then p*p*o = Product I by A2;
  then p*(p*o) = Product ((I | (p-'1)) ^ (I /^ p)) * p by A7,A8;
  then p*o = Product ((I | (p-'1)) ^ (I /^ p)) by XCMPLX_1:5;
  then
A11:p divides Product ((I| (p-'1))^(I /^ p));
  rng ((I| (p-'1))^(I /^ p)) c= NAT;
  then ((I| (p-'1))^(I /^ p)) is FinSequence of NAT by FINSEQ_1:def 4;
  then consider i be Nat such that
A12:i in dom ((I| (p-'1))^(I /^ p)) and
A13:p divides ((I| (p-'1))^(I /^ p)).i by A11,A10,HILB10_5:3;
  1 < p by A5;
  then
A14:p-'1 = p-1 by XREAL_1:233;
  then p-'1 < p-0 by XREAL_1:15;
  then
A15: p-'1 < len I by A5,XXREAL_0:2;
  then
A16:len (I| (p-'1)) = p-'1 by FINSEQ_1:59;
  per cases by A12,FINSEQ_1:25;
  suppose
A17:  i in dom (I| (p-'1));
    then
A18:  ((I| (p-'1))^(I /^ p)).i = (I| (p-'1)).i by FINSEQ_1:def 7
    .= I.i by FUNCT_1:47,A17;
A19:  1<= i <= p-'1 by A16,A17,FINSEQ_3:25;
    then i <= len I by A15,XXREAL_0:2;
    then i in Seg n by A19;
    then I.i = i by FINSEQ_2:49;
    then p divides i by A18,A13;
    then p-'1+1 = p <= i by A14,A19,INT_2:27;
    hence thesis by A19,NAT_1:13;
  end;
  suppose ex k be Nat st k in dom (I /^ p) & i=len (I| (p-'1)) + k;
    then consider k be Nat such that
A20:  k in dom (I /^ p) & i=len (I| (p-'1)) + k;
    k+p in dom I by A20,FINSEQ_5:26;
    then
A21:  k+p in Seg n by A6,FINSEQ_1:def 3;
    ((I| (p-'1))^(I /^ p)).i = (I /^ p).k by A20,FINSEQ_1:def 7
    .= I.(k+p) by A20,A5,RFINSEQ:def 1
    .= k+p by A21,FINSEQ_2:49;
    then p divides k+p by A13;
    then consider o be Nat such that
A22:  p*o = k+p by NAT_D:def 3;
    o <>0 by A22;
    then
A23:  o >=1 by NAT_1:14;
    1<=k by A20,FINSEQ_3:25;
    then k<>0;
    then o <> 1 by A22;
    then o > 1 by A23,XXREAL_0:1;
    then o >= 1+1 by NAT_1:13;
    then k+p >= 2*p by A22,XREAL_1:66;
    then k+p > n by A1,XXREAL_0:2;
    hence thesis by A21,FINSEQ_1:1;
  end;
end;
