Lucas-Lehmer Test:

for 



p


{\displaystyle p}

 an odd prime, the Mersenne number 




2

p


−
1


{\displaystyle 2^{p}-1}

 is prime if and only if 




2

p


−
1


{\displaystyle 2^{p}-1}

 divides 



S
(
p
−
1
)


{\displaystyle S(p-1)}

 where 



S
(
n
+
1
)
=
(
S
(
n
)

)

2


−
2


{\displaystyle S(n+1)=(S(n))^{2}-2}

, and 



S
(
1
)
=
4


{\displaystyle S(1)=4}

.



Task

Calculate all Mersenne primes up to the implementation's
maximum precision, or the 47th Mersenne prime   (whichever comes first).




  ( clk$:?t0:?now
  & ( time
    =   ( print
        =   
          .   put
            $ ( str
              $ ( div$(!arg,1)
                  ","
                  (   div$(mod$(!arg*100,100),1):?arg
                    & !arg:<10
                    & 0
                  | 
                  )
                  !arg
                  " "
                )
              )
        )
      & -1*!now+(clk$:?now):?SEC
      & print$!SEC
      & print$(!now+-1*!t0)
      & put$"s: "
    )
  & 3:?exponent
  &   whl
    ' ( !exponent:~>12000
      & (   !exponent^(!exponent^-1):!exponent^%
          & 4:?s
          & 2^!exponent+-1:?n
          & 0:?i
          &   whl
            ' ( 1+!i:?i
              & !exponent+-2:~<!i
              & mod$(!s^2+-2.!n):?s
              )
          & (   !s:0
              & !time
              & out$(str$(M !exponent " is PRIME!"))
            | 
            )
        | 
        )
      & 1+!exponent:?exponent
      )
  & done
  );