Cullen and Woodall numbers: Difference between revisions

Added Perl
(Added Algol 68)
(Added Perl)
Line 147:
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<lang perl>use strict;
use warnings;
use bigint;
use ntheory 'is_prime';
use constant Inf => 1e10;
 
sub cullen {
my($n,$c) = @_;
($n * 2**$n) + $c;
}
 
my($m,$n);
 
($m,$n) = (20,0);
print "First $m Cullen numbers:\n";
print do { $n < $m ? (++$n and cullen($_,1) . ' ') : last } for 1 .. Inf;
 
($m,$n) = (20,0);
print "\n\nFirst $m Woodall numbers:\n";
print do { $n < $m ? (++$n and cullen($_,-1) . ' ') : last } for 1 .. Inf;
 
($m,$n) = (5,0);
print "\n\nFirst $m Cullen primes: (in terms of n)\n";
print do { $n < $m ? (!!is_prime(cullen $_,1) and ++$n and "$_ ") : last } for 1 .. Inf;
 
($m,$n) = (12,0);
print "\n\nFirst $m Woodall primes: (in terms of n)\n";
print do { $n < $m ? (!!is_prime(cullen $_,-1) and ++$n and "$_ ") : last } for 1 .. Inf;</lang>
{{out}}
<pre>First 20 Cullen numbers:
3 9 25 65 161 385 897 2049 4609 10241 22529 49153 106497 229377 491521 1048577 2228225 4718593 9961473 20971521
 
First 20 Woodall numbers:
1 7 23 63 159 383 895 2047 4607 10239 22527 49151 106495 229375 491519 1048575 2228223 4718591 9961471 20971519
 
First 5 Cullen primes: (in terms of n)
1 141 4713 5795 6611
 
First 12 Woodall primes: (in terms of n)
2 3 6 30 75 81 115 123 249 362 384 462</pre>
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
2,392

edits