CalmoSoft primes: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: fix the basic taks trial division primality test (no really :o, though the bug didn't affect the result) and stop when the next sequence can't be longer than the max) |
SqrtNegInf (talk | contribs) (Added Perl) |
||
Line 1,018: | Line 1,018: | ||
[7, 11, 13, 17, 19, 23, ... 49999699, 49999711, 49999739, 49999751, 49999753, 49999757] |
[7, 11, 13, 17, 19, 23, ... 49999699, 49999711, 49999739, 49999751, 49999753, 49999757] |
||
</pre> |
</pre> |
||
=={{header|Perl}}== |
|||
{{libheader|ntheory}} |
|||
<syntaxhighlight lang="perl" line>use strict; |
|||
use warnings; |
|||
use ntheory <primes is_prime vecsum>; |
|||
for my $limit (<100 250 500 1000>) { |
|||
my @primes = @{ primes(2,$limit) }; |
|||
T: for my $terms (reverse 1 .. @primes) { |
|||
for my $i (0 .. @primes-$terms) { |
|||
my @primes = @primes[$i..($i+$terms)-1]; |
|||
next unless is_prime (my $sum = vecsum @primes); |
|||
print "For primes up to $limit:\n", |
|||
join ' ... ', join(' + ',@primes[0..5]), join(' + ',@primes[-5..-1]) . " = $sum ($terms primes)\n\n"; |
|||
last T |
|||
} |
|||
} |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
<pre>For primes up to 100: |
|||
7 + 11 + 13 + 17 + 19 + 23 ... 71 + 73 + 79 + 83 + 89 = 953 (21 primes) |
|||
For primes up to 250: |
|||
11 + 13 + 17 + 19 + 23 + 29 ... 227 + 229 + 233 + 239 + 241 = 5813 (49 primes) |
|||
For primes up to 500: |
|||
31 + 37 + 41 + 43 + 47 + 53 ... 467 + 479 + 487 + 491 + 499 = 21407 (85 primes) |
|||
For primes up to 1000: |
|||
13 + 17 + 19 + 23 + 29 + 31 ... 971 + 977 + 983 + 991 + 997 = 76099 (163 primes)</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |