Wieferich primes: Difference between revisions

m
→‎{{header|REXX}}: added whitespace and comments, added a "filter" comment.
m (→‎{{header|REXX}}: added whitespace and comments, added a "filter" comment.)
Line 588:
found= 0 /*initialize number of Wieferich primes*/
do j=1 to #; p= @.j /*search for Wieferich primes in range.*/
if (2**(p-1)-1)//p**2\==0 then iterate /*P**2 not evenly divide 2**(P-1) - 1?*/ /* ◄■■■■■■■ the filter.*/
found= found + 1 /*bump the counter of Wieferich primes.*/
say center(found, 7)'│' center(commas(p), w) /*display the Wieferich prime.*/
Line 599:
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: @.1=2; @.2=3; @.3=5; @.4=7; @.5=11 /*define some low primes (index-1). */
!.=0; !.2=1; !.3=1; !.5=1; !.7=1; !.11=1 /* " " " " (semaphores).*/
#= 5; sq.#= @.# **2 2 /*number of primes so far; prime². */
do j=@.#+2 by 2 to n-1; parse var j '' -1 _ /*findget oddright primesdecimal fromdigit hereof onJ.*/
if _==5 then iterate /*get right digit; /*J ÷ by 5? Yes, skip.*/
if j//3==0 then iterate; if j//7==0 then iterate /*J" ÷" by " 3? J ÷ by 7? */
do k=5 while sq.k<=j /* [↓] divide by the known odd primes.*/
if j//@.k==0 then iterate j /*Is J ÷ a P? Then not prime. ___ */