Concatenate two primes is also prime: Difference between revisions
Content added Content deleted
(Ada version) |
(Concatenate two primes is also prime en Yabasic) |
||
Line 313: | Line 313: | ||
</pre> |
</pre> |
||
=={{header| |
=={{header|BASIC}}== |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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. |
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" |
<lang freebasic>#include "isprime.bas" |
||
Line 379: | Line 348: | ||
83|17 83|29 83|53 83|89 89|23 89|29 89|41 89|71 97| 7 97|19 |
83|17 83|29 83|53 83|89 89|23 89|29 89|41 89|71 97| 7 97|19 |
||
97|43 97|67 |
97|43 97|67 |
||
⚫ | |||
==={{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}}== |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</pre> |
</pre> |
||