reserve X for set;
reserve a,b,c,k,m,n for Nat;
reserve i,j for Integer;
reserve r,s for Real;
reserve p,p1,p2,p3 for Prime;

theorem Th52:
  n satisfies_Sierpinski_problem_86 implies
  n-1 is prime & (ex x,y being Prime st x <> y & n+1 = x*y) or
  n+1 is prime & (ex x,y being Prime st x <> y & n-1 = x*y)
  proof
    assume n satisfies_Sierpinski_problem_86;
    then consider a,b,c being Prime such that
A1: a,b,c are_mutually_distinct and
A2: a*b*c = n|^2-1;
A3: n|^2 = n^2 by WSIERP_1:1;
    then
A4: a*b*c = (n-1)*(n+1) by A2;
    c divides a*b*c;
    then
A5: c divides n-1 or c divides n+1 by A4,INT_5:7;
A6: c > 1 by INT_2:def 4;
A7: a*b*c = b*c*a;
A8: a*b*c = a*c*b;
A9: now
      assume 1 > n;
      then n = 0 by NAT_1:14;
      hence contradiction by A2;
    end;
    per cases by A2,Th51;
    suppose
A10:  n-1 is prime;
      then per cases by A5,A6;
      suppose c = n-1;
        hence thesis by A1,A4,XCMPLX_1:5;
      end;
      suppose c divides n+1;
        then c*(n-1) divides (n+1)*(n-1) by NAT_3:1;
        then per cases by A2,A3,A9,A10,GROUP_22:1,GR_CY_3:1;
        suppose a = n-1;
          hence thesis by A1,A4,A7,XCMPLX_1:5;
        end;
        suppose b = n-1;
          hence thesis by A1,A4,A8,XCMPLX_1:5;
        end;
      end;
    end;
    suppose
A11:  n+1 is prime;
      then per cases by A5,A6;
      suppose c = n+1;
        hence thesis by A1,A4,XCMPLX_1:5;
      end;
      suppose c divides n-1;
        then c*(n+1) divides (n-1)*(n+1) by NAT_3:1;
        then per cases by A2,A3,A11,GROUP_22:1,GR_CY_3:1;
        suppose a = n+1;
          hence thesis by A1,A4,A7,XCMPLX_1:5;
        end;
        suppose b = n+1;
          hence thesis by A1,A4,A8,XCMPLX_1:5;
        end;
      end;
    end;
  end;
