Smarandache-Wellin primes: Difference between revisions
Content added Content deleted
(Added C++ solution) |
SqrtNegInf (talk | contribs) (Added Perl) |
||
Line 500: | Line 500: | ||
SmarandacheWellin() |
SmarandacheWellin() |
||
</syntaxhighlight>{{out}} Same as C and Go versions. |
</syntaxhighlight>{{out}} Same as C and Go versions. |
||
=={{header|Perl}}== |
|||
{{libheader|ntheory}} |
|||
<syntaxhighlight lang="perl" line> |
|||
use strict; |
|||
use warnings; |
|||
use ntheory <is_prime next_prime>; |
|||
sub abbr ($d) { my $l = length $d; $l < 41 ? $d : substr($d,0,20) . '..' . substr($d,-20) . " ($l digits)" } |
|||
print "Smarandache-Wellen primes:\n"; |
|||
my($p, $i, $nth, $n) = (0, -1, 0); |
|||
do { |
|||
$p = next_prime($p); |
|||
$n .= $p; |
|||
$i++; |
|||
(printf("$nth: Index:%5d Last prime:%6d S-W: %s\n",$i, $p, abbr $n) and $nth++) if is_prime($n); |
|||
} until $nth == 8; |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Smarandache-Wellen primes: |
|||
1: Index: 0 Last prime: 2 S-W: 2 |
|||
2: Index: 1 Last prime: 3 S-W: 23 |
|||
3: Index: 3 Last prime: 7 S-W: 2357 |
|||
4: Index: 127 Last prime: 719 S-W: 23571113171923293137..73677683691701709719 (355 digits) |
|||
5: Index: 173 Last prime: 1033 S-W: 23571113171923293137..10131019102110311033 (499 digits) |
|||
6: Index: 341 Last prime: 2297 S-W: 23571113171923293137..22732281228722932297 (1171 digits) |
|||
7: Index: 434 Last prime: 3037 S-W: 23571113171923293137..30013011301930233037 (1543 digits) |
|||
8: Index: 1428 Last prime: 11927 S-W: 23571113171923293137..11903119091192311927 (5719 digits) |
|||
</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |