
theorem Th24:
  for n,f,c being Element of NAT st n-1 = f*c & f > c & c > 0 &
  (for q being Element of NAT st q divides f & q is prime
   ex a being Element of NAT st a|^(n-'1) mod n = 1 &
    (a|^((n-'1) div q)-'1) gcd n = 1)
  holds n is prime
proof
  let n,f,c be Element of NAT;
  assume that
A1: n-1=f*c and
A2: f>c and
A3: c>0;
A4: n-1+1>0+1 by A1,A2,A3,XREAL_1:6;
  assume
A5: for q being Element of NAT st q divides f & q is prime holds ex a
being Element of NAT st a|^(n-'1) mod n = 1 & (a|^((n-'1) div q)-'1) gcd n = 1;
  assume not n is prime;
  then consider p be Element of NAT such that
A6: p divides n and
A7: 1<p and
A8: p*p<=n and
A9: p is prime by A4,Lm1;
A10: p-1=p-'1 by A7,XREAL_1:233;
A11: p-1>1-1 by A7,XREAL_1:9;
  then
A12: p-'1>0 by A7,XREAL_1:233;
A13: for q1 being Element of NAT st q1 in support (pfexp f) & q1 |-count f >
  0 holds p mod q1|^(q1 |-count f) = 1
  proof
    let q1 be Element of NAT;
    set n1=q1 |-count f;
    assume
A14: q1 in support (pfexp f);
    then
A15: q1 is prime by NAT_3:34;
A16: q1 is prime by A14,NAT_3:34;
    then consider a be Element of NAT such that
A17: a|^(n-'1) mod n = 1 and
A18: (a|^((n-'1) div q1)-'1) gcd n = 1 by A5,A14,NAT_3:36;
    assume
A19: q1 |-count f > 0;
A20: not p divides (a|^((n-'1) div q1)-'1)
    by A6,NEWTON:50,A7,A18,NAT_D:7;
    q1<>1 by A16,INT_2:def 4;
    then q1|^(q1 |-count f) divides f by A2,NAT_3:def 7;
    then consider d be Nat such that
A21: f=q1|^n1*d by NAT_D:def 3;
    reconsider d as Element of NAT by ORDINAL1:def 12;
    set k=d*c;
A22: k>0
    proof
      assume k<=0;
      then d=0 by A3;
      hence contradiction by A2,A21;
    end;
    n-1=k*q1|^n1 by A1,A21;
    hence thesis by A6,A9,A19,A17,A22,A15,A20,Th23;
  end;
  for q1 being Element of NAT st q1 is prime holds q1 |-count f <= q1
  |-count (p-'1)
  proof
    let q1 be Element of NAT;
    assume
A23: q1 is prime;
    per cases;
    suppose
A24:  q1 in support (pfexp f);
      then (pfexp f).q1<>0 by PRE_POLY:def 7;
      then q1 |-count f>0 by A23,NAT_3:def 8;
      then p mod q1|^(q1 |-count f) = 1 by A13,A24;
      then
A25:  q1 |-count (q1|^(q1 |-count f)) <= q1 |-count (p-'1) by A11,A10,A23,
NAT_3:30,PEPIN:8;
      q1>1 by A23,INT_2:def 4;
      hence thesis by A25,NAT_3:25;
    end;
    suppose
      not q1 in support (pfexp f);
      then (pfexp f).q1=0 by PRE_POLY:def 7;
      hence thesis by A23,NAT_3:def 8;
    end;
  end;
  then ex n2 being Element of NAT st (p-'1)=f*n2 by A2,A12,Th20;
  then f divides (p-'1) by NAT_D:def 3;
  then f<=(p-'1) by A12,NAT_D:7;
  then p-1+1>=f+1 by A10,XREAL_1:6;
  then p>f by NAT_1:13;
  then
A26: p^2>f^2 by SQUARE_1:16;
  c>=0+1 by A3,NAT_1:13;
  then
A27: c+1>=1+1 by XREAL_1:6;
  f>=c+1 by A2,NAT_1:13;
  then f>=2 by A27,XXREAL_0:2;
  then f-1>=2-1 by XREAL_1:9;
  then
A28: n+(f-1)>=n+1 by XREAL_1:6;
  f>=c+1 by A2,NAT_1:13;
  then f*f>=f*(c+1) by XREAL_1:64;
  then p^2>f+(n-1) by A1,A26,XXREAL_0:2;
  then p^2>=n+1 by A28,XXREAL_0:2;
  hence contradiction by A8,NAT_1:13;
end;
