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;
reserve z for Complex;

theorem Th23:
  for p,q being Prime st p is odd & q divides Mersenne(p)
  ex k being Nat st q = 2*k*p+1
  proof
    let p,q be Prime such that
A1: p is odd;
    assume
A2: q divides Mersenne(p);
    then 2|^p,1 are_congruent_mod q;
    then
A3: (2|^p) mod q = 1 mod q by NAT_D:64;
A4: q > 1 by INT_2:def 4;
A5: now
      assume q <= 2;
      then q = 0 or ... or q = 2;
      hence contradiction by A2,INT_2:def 4;
    end;
    then
A6: 2,q are_coprime by XPRIMES1:2,INT_2:30;
A7: now
      assume order(2,q) = 1;
      then (2|^1) mod q = 1 by A4,A6,PEPIN:def 2;
      hence contradiction by A5,NAT_D:24;
    end;
    order(2,q) divides p by A3,A4,A6,PEPIN:47,NAT_D:24;
    then
A8: p = order(2,q) by A7,INT_2:def 4;
A9: Euler q = q-1 by EULER_1:20;
    (2 |^ Euler q) mod q = 1 by A6,EULER_2:18,INT_2:def 4;
    then p divides q-1 by A4,A6,A8,A9,PEPIN:47;
    then consider w being Nat such that
A10: q-1 = p*w;
A11: q = p*w+1 by A10;
    then w is even by A1,A5,PEPIN:17;
    then consider e being Nat such that
A12: w = 2*e;
    take e;
    thus thesis by A11,A12;
  end;
