Concatenate two primes is also prime: Difference between revisions

add FreeBASIC
m (→‎{{header|REXX}}: expanded output title, added/changed comments and whitespace.)
(add FreeBASIC)
Line 205:
 
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"
dim as integer p1, p2, cat, c = 0
 
for p1 = 2 to 99
if not isprime(p1) then continue for
for p2 = 2 to 99
if not isprime(p2) then continue for
cat = val( str(p1) + str(p2) ) ' =^..^=
if isprime(cat) then
c+=1
print using "##|## ";p1;p2;
if c mod 10 = 0 then print
end if
next p2
next p1
</lang>
{{out}}<pre>
2| 3 2|11 2|23 2|29 2|41 2|71 2|83 3| 7 3|11 3|13
3|17 3|31 3|37 3|47 3|53 3|59 3|67 3|73 3|79 3|83
3|89 3|97 5| 3 5|23 5|41 5|47 5|71 7| 3 7|19 7|43
7|61 7|73 7|97 11| 3 11|17 11|23 11|29 11|53 11|71 13| 7
13|19 13|61 13|67 13|73 17| 3 17|23 17|41 17|47 17|53 17|59
17|83 17|89 19| 3 19| 7 19|13 19|31 19|73 19|79 19|97 23| 3
23|11 23|41 23|47 23|71 23|83 23|89 29| 3 29|17 29|53 29|71
31| 3 31| 7 31|19 31|37 31|67 37| 3 37|19 37|61 37|67 37|79
37|97 41|11 41|29 41|53 41|59 43| 3 43|37 43|73 43|97 47|23
47|29 47|59 47|83 47|89 53|23 53|47 59| 3 59|23 59|53 61| 3
61| 7 61|13 61|31 61|43 61|73 61|97 67| 3 67| 7 67|19 67|37
67|61 67|79 71|29 71|59 73| 3 73|31 79| 7 79|19 79|37 83|11
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>
 
781

edits