Cullen and Woodall numbers: Difference between revisions

Add PARI/GP implementation
m (→‎{{header|Wren}}: Minor tidy)
(Add PARI/GP implementation)
Line 1,175:
First 12 Woodall primes (in terms of n):
2 3 6 30 75 81 115 123 249 362 384 462
</pre>
 
=={{header|PARI/GP}}==
<syntaxhighlight lang="PARI/GP">
/* Define the Cullen and Woodall number functions */
cullen(n) = n * 2^n + 1;
woodall(n) = n * 2^n - 1;
 
{
/* Generate the first 20 Cullen and Woodall numbers */
print(vector(20, n, cullen(n)));
print(vector(20, n, woodall(n)));
 
/* Find the first 5 Cullen prime numbers */
cps = [];
for(i = 1, +oo,
if(isprime(cullen(i)),
cps = concat(cps, i);
if(#cps >= 5, break);
);
);
print(cps);
 
/* Find the first 12 Woodall prime numbers */
wps = [];
for(i = 1, +oo,
if(isprime(woodall(i)),
wps = concat(wps, i);
if(#wps >= 12, break);
);
);
print(wps);
}
</syntaxhighlight>
{{out}}
<pre>
[3, 9, 25, 65, 161, 385, 897, 2049, 4609, 10241, 22529, 49153, 106497, 229377, 491521, 1048577, 2228225, 4718593, 9961473, 20971521]
[1, 7, 23, 63, 159, 383, 895, 2047, 4607, 10239, 22527, 49151, 106495, 229375, 491519, 1048575, 2228223, 4718591, 9961471, 20971519]
[1, 141, 4713, 5795, 6611]
[2, 3, 6, 30, 75, 81, 115, 123, 249, 362, 384, 462]
 
</pre>
 
338

edits