Cullen and Woodall numbers: Difference between revisions

Content deleted Content added
Realize in F#
Added Algol 68
Line 39: Line 39:
* [[oeis:A002234|OEIS:A002234 - Numbers k such that the Woodall number k*2^k - 1 is prime]]
* [[oeis:A002234|OEIS:A002234 - Numbers k such that the Woodall number k*2^k - 1 is prime]]



=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses Algol 68Gs LONG LONG INT for long integers. The number of digits must be specified and appears to affect the run time as larger sies are specified. This sample only shows the first two Cullen primes as the time taken to find the third is rather long.
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find Cullen and Woodall numbers and determine which are prime #
# a Cullen number n is n2^2 + 1, Woodall number is n2^n - 1 #
PR read "primes.incl.a68" PR # include prime utilities #
PR precision 800 PR # set number of digits for Algol 68G LONG LONG INT #
# returns the nth Cullen number #
OP CULLEN = ( INT n )LONG LONG INT: n * LONG LONG INT(2)^n + 1;
# returns the nth Woodall number #
OP WOODALL = ( INT n )LONG LONG INT: CULLEN n - 2;

# show the first 20 Cullen numbers #
print( ( "1st 20 Cullen numbers:" ) );
FOR n TO 20 DO
print( ( " ", whole( CULLEN n, 0 ) ) )
OD;
print( ( newline ) );
# show the first 20 Woodall numbers #
print( ( "1st 20 Woodall numbers:" ) );
FOR n TO 20 DO
print( ( " ", whole( WOODALL n, 0 ) ) )
OD;
print( ( newline ) );
BEGIN # first 2 Cullen primes #
print( ( "Index of the 1st 2 Cullen primes:" ) );
LONG LONG INT power of 2 := 1;
INT prime count := 0;
FOR n WHILE prime count < 2 DO
power of 2 *:= 2;
LONG LONG INT c n = ( n * power of 2 ) + 1;
IF is probably prime( c n ) THEN
prime count +:= 1;
print( ( " ", whole( n, 0 ) ) )
FI
OD;
print( ( newline ) )
END;
BEGIN # first 12 Woodall primes #
print( ( "Index of the 1st 12 Woodall primes:" ) );
LONG LONG INT power of 2 := 1;
INT prime count := 0;
FOR n WHILE prime count < 12 DO
power of 2 *:= 2;
LONG LONG INT w n = ( n * power of 2 ) - 1;
IF is probably prime( w n ) THEN
prime count +:= 1;
print( ( " ", whole( n, 0 ) ) )
FI
OD;
print( ( newline ) )
END
END</lang>
{{out}}
<pre>
1st 20 Cullen numbers: 3 9 25 65 161 385 897 2049 4609 10241 22529 49153 106497 229377 491521 1048577 2228225 4718593 9961473 20971521
1st 20 Woodall numbers: 1 7 23 63 159 383 895 2047 4607 10239 22527 49151 106495 229375 491519 1048575 2228223 4718591 9961471 20971519
Index of the 1st 2 Cullen primes: 1 141
Index of the 1st 12 Woodall primes: 2 3 6 30 75 81 115 123 249 362 384 462
</pre>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
Line 56: Line 118:
1 141 4713 5795 6611
1 141 4713 5795 6611
</pre>
</pre>

=={{header|Julia}}==
=={{header|Julia}}==
{{trans|Raku}}
{{trans|Raku}}