Factorial primes: Difference between revisions
Content added Content deleted
m (→{{header|LOLCODE}}: Add missing "AN" - which seems to be optional) |
(julia example) |
||
Line 94: | Line 94: | ||
(i.28x here would have given us an eleventh prime, but the task asked for the first 10, and the stretch goal requires considerable patience.) |
(i.28x here would have given us an eleventh prime, but the task asked for the first 10, and the stretch goal requires considerable patience.) |
||
=={{header|Julia}}== |
|||
<lang ruby>using Primes |
|||
limitedprint(n) = (s = string(n); n = length(s); return n <= 40 ? s : s[1:20] * "..." * s[end-20:end] * " ($n digits)") |
|||
function showfactorialprimes(N) |
|||
for i in big"1":N |
|||
f = factorial(i) |
|||
isprime(f - 1) && println(i, "! - 1 -> ", limitedprint(f - 1)) |
|||
isprime(f + 1) && println(i, "! + 1 -> ", limitedprint(f + 1)) |
|||
end |
|||
end |
|||
showfactorialprimes(1000) |
|||
</lang>{{out}} |
|||
<pre> |
|||
1! + 1 -> 2 |
|||
2! + 1 -> 3 |
|||
3! - 1 -> 5 |
|||
3! + 1 -> 7 |
|||
4! - 1 -> 23 |
|||
6! - 1 -> 719 |
|||
7! - 1 -> 5039 |
|||
11! + 1 -> 39916801 |
|||
12! - 1 -> 479001599 |
|||
14! - 1 -> 87178291199 |
|||
27! + 1 -> 10888869450418352160768000001 |
|||
30! - 1 -> 265252859812191058636308479999999 |
|||
32! - 1 -> 263130836933693530167218012159999999 |
|||
33! - 1 -> 8683317618811886495518194401279999999 |
|||
37! + 1 -> 13763753091226345046...979581580902400000001 (44 digits) |
|||
38! - 1 -> 52302261746660111176...224100074291199999999 (45 digits) |
|||
41! + 1 -> 33452526613163807108...440751665152000000001 (50 digits) |
|||
73! + 1 -> 44701154615126843408...903680000000000000001 (106 digits) |
|||
77! + 1 -> 14518309202828586963...248000000000000000001 (114 digits) |
|||
94! - 1 -> 10873661566567430802...999999999999999999999 (147 digits) |
|||
116! + 1 -> 33931086844518982011...000000000000000000001 (191 digits) |
|||
154! + 1 -> 30897696138473508879...000000000000000000001 (272 digits) |
|||
166! - 1 -> 90036917057784373664...999999999999999999999 (298 digits) |
|||
320! + 1 -> 21161033472192524829...000000000000000000001 (665 digits) |
|||
324! - 1 -> 22889974601791023211...999999999999999999999 (675 digits) |
|||
340! + 1 -> 51008644721037110809...000000000000000000001 (715 digits) |
|||
379! - 1 -> 24840307460964707050...999999999999999999999 (815 digits) |
|||
399! + 1 -> 16008630711655973815...000000000000000000001 (867 digits) |
|||
427! + 1 -> 29063471769607348411...000000000000000000001 (940 digits) |
|||
469! - 1 -> 67718096668149510900...999999999999999999999 (1051 digits) |
|||
546! - 1 -> 14130200926141832545...999999999999999999999 (1260 digits) |
|||
872! + 1 -> 19723152008295244962...000000000000000000001 (2188 digits) |
|||
974! - 1 -> 55847687633820181096...999999999999999999999 (2490 digits) |
|||
</pre> |
|||
=={{header|LOLCODE}}== |
=={{header|LOLCODE}}== |