Concatenate two primes is also prime: Difference between revisions

Concatenate two primes is also prime en Yabasic
(Ada version)
(Concatenate two primes is also prime en Yabasic)
Line 313:
</pre>
 
=={{header|FactorBASIC}}==
{{works with|Factor|0.99 2021-06-02}}
<lang factor>USING: formatting grouping io kernel math.parser math.primes
present prettyprint sequences sets sorting ;
 
==={{header|FreeBASIC}}===
"Concatenated-pair primes from primes < 100:" print nl
99 primes-upto [ present ] map dup [ append dec> ] cartesian-map
concat [ prime? ] filter members natural-sort [ length ] keep
8 group simple-table. "\nFound %d concatenated primes.\n" printf</lang>
{{out}}
<pre>
Concatenated-pair primes from primes < 100:
 
23 37 53 73 113 137 173 193
197 211 223 229 233 241 271 283
293 311 313 317 331 337 347 353
359 367 373 379 383 389 397 433
523 541 547 571 593 613 617 673
677 719 733 743 761 773 797 977
1117 1123 1129 1153 1171 1319 1361 1367
1373 1723 1741 1747 1753 1759 1783 1789
1913 1931 1973 1979 1997 2311 2341 2347
2371 2383 2389 2917 2953 2971 3119 3137
3167 3719 3761 3767 3779 3797 4111 4129
4153 4159 4337 4373 4397 4723 4729 4759
4783 4789 5323 5347 5923 5953 6113 6131
6143 6173 6197 6719 6737 6761 6779 7129
7159 7331 7919 7937 8311 8317 8329 8353
8389 8923 8929 8941 8971 9719 9743 9767
 
Found 128 concatenated primes.
</pre>
 
=={{header|FreeBASIC}}==
This solution focuses more on the primes p1, p2 than on the concatenated prime. Thus, there can be multiple solutions. For example, 373 can be formed from 37 and 3 or from 3 and 73 and will be listed twice.
<lang freebasic>#include "isprime.bas"
Line 379 ⟶ 348:
83|17 83|29 83|53 83|89 89|23 89|29 89|41 89|71 97| 7 97|19
97|43 97|67
</pre>
 
==={{header|Yabasic}}===
<lang yabasic>c = 0
for p1 = 2 to 99
if not isPrime(p1) then continue : fi
for p2 = 2 to 99
if not isPrime(p2) then continue : fi
cat = val(str$(p1) + str$(p2))
if isPrime(cat) then
c = c + 1
a$ = str$(p1,"##")
b$ = str$(p2,"##")
print a$, "|", b$, " ";
if mod(c, 10) = 0 then print : fi
end if
next p2
next p1
print
end
 
sub isPrime(v)
if v < 2 then return False : fi
if mod(v, 2) = 0 then return v = 2 : fi
if mod(v, 3) = 0 then return v = 3 : fi
d = 5
while d * d <= v
if mod(v, d) = 0 then return False else d = d + 2 : fi
wend
return True
end sub</lang>
 
 
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<lang factor>USING: formatting grouping io kernel math.parser math.primes
present prettyprint sequences sets sorting ;
 
"Concatenated-pair primes from primes < 100:" print nl
99 primes-upto [ present ] map dup [ append dec> ] cartesian-map
concat [ prime? ] filter members natural-sort [ length ] keep
8 group simple-table. "\nFound %d concatenated primes.\n" printf</lang>
{{out}}
<pre>
Concatenated-pair primes from primes < 100:
 
23 37 53 73 113 137 173 193
197 211 223 229 233 241 271 283
293 311 313 317 331 337 347 353
359 367 373 379 383 389 397 433
523 541 547 571 593 613 617 673
677 719 733 743 761 773 797 977
1117 1123 1129 1153 1171 1319 1361 1367
1373 1723 1741 1747 1753 1759 1783 1789
1913 1931 1973 1979 1997 2311 2341 2347
2371 2383 2389 2917 2953 2971 3119 3137
3167 3719 3761 3767 3779 3797 4111 4129
4153 4159 4337 4373 4397 4723 4729 4759
4783 4789 5323 5347 5923 5953 6113 6131
6143 6173 6197 6719 6737 6761 6779 7129
7159 7331 7919 7937 8311 8317 8329 8353
8389 8923 8929 8941 8971 9719 9743 9767
 
Found 128 concatenated primes.
</pre>
 
2,122

edits