Anonymous user
Concatenate two primes is also prime: Difference between revisions
Concatenate two primes is also prime (view source)
Revision as of 18:56, 12 September 2021
, 2 years ago→{{header|REXX}}: expanded output title, added/changed comments and whitespace.
m (→{{header|REXX}}: expanded output title, added/changed comments and whitespace.) |
|||
Line 481:
=={{header|REXX}}==
<lang rexx>/*REXX pgm finds
parse arg hip cols . /*obtain optional arguments from the CL*/
if hip=='' | hip=="," then hip= 100 /*Not specified? Then use the default.*/
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
call genP /*build array of semaphores for primes.*/
title= ' concatenation of two neighbor primes (P1, P2) in base ten that results in
"a
w= 10 /*width of a number in any column. */
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) )
Line 494:
do j=1 for ## /*search through specified primes. */
do k=1 for ##; cat2= @.j || @.k /*create a concatenated prime (base 10)*/
if !.cat2 then a.cat2= 1 /*flag it as being a "2cat" prime. */
end /*k*/ /* [↑] forgoes the need for sorting. */
end /*j*/
found= 0;
$=; do n=1 by 2 for hip**2%2 /*search for odd "cat2" primes. */
if \a.n then iterate /*search through allowable primes. */
Line 512:
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found '
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 521:
#= 5; sq.#= @.#**2 /*the square of the highest low prime. */
do j=@.#+2 by 2 to hip**2-1 /*find odd primes from here on. */
parse var j '' -1 _;
if j//3==0 then
do k=5 while sq.k<=j /* [↓] divide by the known odd primes.*/
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */
Line 532 ⟶ 531:
{{out|output|text= when using the default inputs:}}
<pre>
index │
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 23 37 53 73 113 137 173 193 197 211
Line 549 ⟶ 548:
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
Found 128 concatenation of two neighbor primes (P1, P2) in base ten that results in a prime,
</pre>
|