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

theorem Th44:
  for p,q being Prime, n being Nat st p*(p+1) + q*(q+1) = n*(n+1) holds
  p = 2 & q = 2 & n = 3 or p = 5 & q = 3 & n = 6 or p = 3 & q = 5 & n = 6
  proof
    let p,q be Prime;
    let n be Nat;
    assume p*(p+1) + q*(q+1) = n*(n+1);
    then
A1: p*(p+1) = (n-q) * (n+q+1);
A2: now
      assume n <= q;
      then n-q <= q-q by XREAL_1:9;
      then n-q <= 0;
      hence contradiction by A1;
    end;
    then
A3: n-q > q-q by XREAL_1:9;
A4: n-q in NAT by A2,INT_1:5;
    p divides p*(p+1);
    then per cases by A1,INT_5:7;
    suppose p divides n-q;
      then
A5:   p <= n-q by A3,INT_2:27;
      then
A6:   p+1 <= n-q+1 by XREAL_1:6;
      p*(p+1) <= (n-q)*(p+1) by A5,XREAL_1:64;
      then n+q+1 <= p+1 by A1,A3,XREAL_1:68;
      then n+q+1 <= n-q+1 by A6,XXREAL_0:2;
      then n+q <= n-q by XREAL_1:8;
      hence thesis by XREAL_1:6;
    end;
    suppose p divides n+q+1;
      then consider k such that
A7:   n+q+1 = p*k by NAT_D:def 3;
A8:   p*(p+1) = (n-q)*(p*k) by A1,A7;
      (n-q)*k*p/p = (n-q)*k by XCMPLX_1:89;
      then
A9:   p+1 = k*(n-q) by A8,XCMPLX_1:89;
      k = 0 or k >= 0+1 by NAT_1:13;
      then per cases by XXREAL_0:1;
      suppose k = 0;
        hence thesis by A7;
      end;
      suppose k = 1;
        hence thesis by A7,A9;
      end;
      suppose k > 1;
        then
A10:     k+1 > 1+1 by XREAL_1:8;
A11:     2*q = k*p-1-(n-q) by A7
        .= k*(k*(n-q)-1)-1-(n-q) by A9
        .= (k+1) * ((k-1)*(n-q)-1);
        then k+1 divides 2*q;
        then per cases by A10,GR_CY_3:1,XPRIMES1:2;
        suppose
A12:       k+1 = q;
A13:       2*q/q = 2 by XCMPLX_1:89;
          1 < q by INT_2:def 4;
          then 1+1 <= q by NAT_1:13;
          then
A14:       q-2 in NAT by INT_1:5;
          2 = ((k-1)*(n-q)-1) by A12,A11,A13,XCMPLX_1:89;
          then per cases by A12,A14,A4,Th26,XPRIMES1:3;
          suppose q-2 = 1 & n-q = 3;
            then q = 3 & n = 6;
            hence thesis by A9,A12;
          end;
          suppose q-2 = 3 & n-q = 1;
            then q = 5 & n = 6;
            hence thesis by A9,A12;
          end;
        end;
        suppose
A15:       k+1 = 2*q;
          then (k+1)*1 = (k+1)*((k-1)*(n-q)-1) by A11;
          then 1 = (k-1)*(n-q)-1 by XCMPLX_1:5;
          then 2*(q-1)*(n-q) = 2*1 by A15;
          then (q-1)*(n-q) = 1;
          then q-1 = 1 & n-q = 1 by A4,NAT_1:15;
          then q = 2 & n = 3;
          hence thesis by A9,A15;
        end;
      end;
    end;
  end;
