Anonymous user
Lucas-Lehmer test: Difference between revisions
m
→{{header|REXX}}: corrected verb conjugation, added comments, changed (title) header, added whitespace, enforced correct numeric form (scientific), added DO-END comment labels. -- ~~~~
(added Bracmat) |
m (→{{header|REXX}}: corrected verb conjugation, added comments, changed (title) header, added whitespace, enforced correct numeric form (scientific), added DO-END comment labels. -- ~~~~) |
||
Line 1,113:
conducive to find large primes.
<lang rexx>/*REXX program to use Lucas-Lehmer primality test for prime powers of 2.*/
parse arg limit . /*get the argument (if any). */
if limit=='' then limit=1000 /*if no argument, assume 1000. */
Line 1,118 ⟶ 1,119:
do j=1 by 2 to limit /*only process so much... */
power=j
if j==1 then power=2 /*special case for the even prime*/
if \isprime(power) then iterate /*if not prime, then ignore it. */
list=list Lucas_Lehmer2(power) /*add to list (or maybe not). */
end /*j*/
list=space(list) /*remove extraneous blanks. */
say; say center('list',60-3,"═") /*show a fancy-dancy header/title*/
say
end /*k*/▼
▲ say right(word(list,j),30) /*and right-justify 'em. */
say
exit
/*──────────────────────────────────LUCAS_LEHMER2 subroutine────────────*/
Lucas_Lehmer2: procedure; parse arg ? /*Lucas-Lehmer test on 2**? - 1 */
numeric form /*ensure correct scientific form.*/
if ?==2 then s=0
else s=4
/* DIGITs of 1 million could be used, but that really */
/* slows up the whole works. So, we start with the */
Line 1,159 ⟶ 1,156:
q=2**?-1 /*now, compute the real McCoy. */
end
▲ s=(s*s-2)//q /*modulus in REXX is: // */
▲ end
if s\==0 then return '' /*return nuttin' if not prime. */
return 'M'? /*return modified (prime) number.*/
/*──────────────────────────────────ISPRIME subroutine──────────────────*/
isprime: procedure; parse arg x; if x<2 then return 0
if wordpos(x,'2 3 5 7')\==0 then return 1 /*test for special cases.*/
if x//3==0 then return 0 /*divisible by three? Not prime.*/
Line 1,177 ⟶ 1,173:
end /*j*/</lang>
'''output''' when the following is used: <tt> 10000 </tt>
<pre style="
══════════════════════════list═══════════════════════════
M2
|