Ultra useful primes: Difference between revisions
Content added Content deleted
m (julia example) |
(Added Algol 68) |
||
Line 20: | Line 20: | ||
* [[oeis:A058220|OEIS:A058220 - Ultra-useful primes: smallest k such that 2^(2^n) - k is prime]] |
* [[oeis:A058220|OEIS:A058220 - Ultra-useful primes: smallest k such that 2^(2^n) - k is prime]] |
||
=={{header|ALGOL 68}}== |
|||
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} |
|||
Uses Algol 68G's LONG LONG INT which has programmer-specifiable precision. Uses Miller Rabin primality testing. |
|||
{{libheader|ALGOL 68-primes}} |
|||
<lang algol68>BEGIN # find members of the sequence a(n) = smallest k such that 2^(2^n) - k is prime # |
|||
PR precision 650 PR # set number of digits for LONG LOMG INT # |
|||
# 2^(2^10) has 308 digits but we need more for # |
|||
# Miller Rabin primality testing # |
|||
PR read "primes.incl.a68" PR # include the prime related utilities # |
|||
FOR n TO 10 DO |
|||
LONG LONG INT two up 2 up n = LONG LONG INT( 2 ) ^ ( 2 ^ n ); |
|||
FOR i BY 2 |
|||
WHILE BOOL found a prime = is probably prime( two up 2 up n - i ); |
|||
IF found a prime THEN |
|||
# found a sequence member # |
|||
print( ( " ", whole( i, 0 ) ) ); |
|||
FALSE # stop looking # |
|||
ELSE |
|||
TRUE # haven't found a sequence member yet # |
|||
FI |
|||
DO SKIP OD |
|||
OD |
|||
END</lang> |
|||
{{out}} |
|||
<pre> |
|||
1 3 5 15 5 59 159 189 569 105 |
|||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |