Ramanujan primes/twins: Difference between revisions
Content added Content deleted
m (added the Prime Numbers category.) |
SqrtNegInf (talk | contribs) (Added Perl) |
||
Line 246: | Line 246: | ||
Elapsed time: 1139 ms</pre> |
Elapsed time: 1139 ms</pre> |
||
=={{header|Perl}}== |
|||
Can't do better than the <code>ntheory</code> module. |
|||
{{libheader|ntheory}} |
|||
<lang perl>use strict; |
|||
use warnings; |
|||
use ntheory <ramanujan_primes nth_ramanujan_prime>; |
|||
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r } |
|||
my $rp = ramanujan_primes nth_ramanujan_prime 1_000_000; |
|||
for my $limit (1e5, 1e6) { |
|||
printf "The %sth Ramanujan prime is %s\n", comma($limit), comma $rp->[$limit-1]; |
|||
printf "There are %s twins in the first %s Ramanujan primes.\n\n", |
|||
comma( scalar grep { $rp->[$_+1] == $rp->[$_]+2 } 0 .. $limit-2 ), comma $limit; |
|||
}</lang> |
|||
{{out}} |
|||
<pre>The 100,000th Ramanujan prime is 2,916,539 |
|||
There are 8,732 twins in the first 100,000 Ramanujan primes. |
|||
The 1,000,000th Ramanujan prime is 34,072,993 |
|||
There are 74,973 twins in the first 1,000,000 Ramanujan primes.</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |