Factorial primes: Difference between revisions

Add Mathematica/Wolfram Language implementation
(Added PureBasic)
(Add Mathematica/Wolfram Language implementation)
(3 intermediate revisions by 3 users not shown)
Line 337:
using big_int = mpz_class;
 
std::string to_string(const big_int& num, size_t nmax_digits) {
std::string str = num.get_str();
size_t len = str.size();
if (len > nmax_digits) {
str = str.substrreplace(0, nmax_digits / 2), +len - max_digits, "..." + str.substr(len - n / 2);
str += " (";
str += std::to_string(len);
Line 482:
10: 14! - 1 = 87178291199
</pre>
 
 
=={{header|EasyLang}}==
{{trans|Lua}}
<syntaxhighlight>
func isprim num .
if num < 2
return 0
.
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
f = 1
while count < 10
n += 1
f *= n
op$ = "-"
for fp in [ f - 1 f + 1 ]
if isprim fp = 1
count += 1
print n & "! " & op$ & " 1 = " & fp
.
op$ = "+"
.
.
</syntaxhighlight>
 
 
Line 997 ⟶ 1,029:
9: 12! - 1 = 479001599
10: 14! - 1 = 87178291199
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
{{trans|Julia}}
<syntaxhighlight lang="Mathematica">
LimitedPrint[n_] := Module[{s = IntegerString[n], len},
len = StringLength[s];
If[len <= 40, s, StringJoin[StringTake[s, 20], "...", StringTake[s, -20], " (", ToString[len], " digits)"]]
]
 
ShowFactorialPrimes[N_] := Module[{f},
Do[
f = Factorial[i];
If[PrimeQ[f - 1], Print[IntegerString[i, 10, 3], "! - 1 -> ", LimitedPrint[f - 1]]];
If[PrimeQ[f + 1], Print[IntegerString[i, 10, 3], "! + 1 -> ", LimitedPrint[f + 1]]],
{i, 1, N}
]
]
 
ShowFactorialPrimes[1000]
</syntaxhighlight>
{{out}}
<pre>
001! + 1 -> 2
002! + 1 -> 3
003! - 1 -> 5
003! + 1 -> 7
004! - 1 -> 23
006! - 1 -> 719
007! - 1 -> 5039
011! + 1 -> 39916801
012! - 1 -> 479001599
014! - 1 -> 87178291199
027! + 1 -> 10888869450418352160768000001
030! - 1 -> 265252859812191058636308479999999
032! - 1 -> 263130836933693530167218012159999999
033! - 1 -> 8683317618811886495518194401279999999
037! + 1 -> 13763753091226345046...79581580902400000001 (44 digits)
038! - 1 -> 52302261746660111176...24100074291199999999 (45 digits)
041! + 1 -> 33452526613163807108...40751665152000000001 (50 digits)
073! + 1 -> 44701154615126843408...03680000000000000001 (106 digits)
077! + 1 -> 14518309202828586963...48000000000000000001 (114 digits)
094! - 1 -> 10873661566567430802...99999999999999999999 (147 digits)
116! + 1 -> 33931086844518982011...00000000000000000001 (191 digits)
154! + 1 -> 30897696138473508879...00000000000000000001 (272 digits)
166! - 1 -> 90036917057784373664...99999999999999999999 (298 digits)
320! + 1 -> 21161033472192524829...00000000000000000001 (665 digits)
324! - 1 -> 22889974601791023211...99999999999999999999 (675 digits)
340! + 1 -> 51008644721037110809...00000000000000000001 (715 digits)
379! - 1 -> 24840307460964707050...99999999999999999999 (815 digits)
399! + 1 -> 16008630711655973815...00000000000000000001 (867 digits)
427! + 1 -> 29063471769607348411...00000000000000000001 (940 digits)
469! - 1 -> 67718096668149510900...99999999999999999999 (1051 digits)
546! - 1 -> 14130200926141832545...99999999999999999999 (1260 digits)
872! + 1 -> 19723152008295244962...00000000000000000001 (2188 digits)
974! - 1 -> 55847687633820181096...99999999999999999999 (2490 digits)
 
</pre>
 
Line 1,717 ⟶ 1,806:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./fmt" for Fmt
 
Line 1,753 ⟶ 1,842:
{{libheader|Wren-gmp}}
This takes about 28.5 seconds to reach the 33rd factorial prime on my machine (Core i7) with the last two being noticeably slower to emerge. Likely to be very slow after that as the next factorial prime is 1477! + 1.
<syntaxhighlight lang="ecmascriptwren">import "./gmp" for Mpz
import "./fmt" for Fmt
 
337

edits