Factorial primes: Difference between revisions
Content added Content deleted
(→{{header|jq}}: factorial primes) |
(Added XPL0 example.) |
||
Line 570: | Line 570: | ||
32: 872! + 1 = 19723152008295244962...00000000000000000001 (2188 digits) |
32: 872! + 1 = 19723152008295244962...00000000000000000001 (2188 digits) |
||
33: 974! - 1 = 55847687633820181096...99999999999999999999 (2490 digits) |
33: 974! - 1 = 55847687633820181096...99999999999999999999 (2490 digits) |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<syntaxhighlight lang "XPL0">func IsPrime(N); \Return 'true' if N is prime |
|||
real N; int I; |
|||
[if N <= 2. then return N = 2.; |
|||
if Mod(N, 2.) = 0. then \even\ return false; |
|||
for I:= 3 to fix(sqrt(N)) do |
|||
[if Mod(N, float(I)) = 0. then return false; |
|||
I:= I+1; |
|||
]; |
|||
return true; |
|||
]; |
|||
func real Factorial(N); \Return N! |
|||
int N; real F; |
|||
[F:= float(N); |
|||
while N > 1 do |
|||
[N:= N-1; |
|||
F:= F * float(N); |
|||
]; |
|||
return F; |
|||
]; |
|||
int N, C; real F; |
|||
[N:= 1; C:= 0; |
|||
Format(1, 0); |
|||
repeat F:= Factorial(N); |
|||
if IsPrime(F-1.) then |
|||
[IntOut(0, N); |
|||
Text(0, "! - 1 = "); |
|||
RlOut(0, F-1.); |
|||
CrLf(0); |
|||
C:= C+1; |
|||
]; |
|||
if IsPrime(F+1.) then |
|||
[IntOut(0, N); |
|||
Text(0, "! + 1 = "); |
|||
RlOut(0, F+1.); |
|||
CrLf(0); |
|||
C:= C+1; |
|||
]; |
|||
N:= N+1; |
|||
until C >= 10; |
|||
]</syntaxhighlight> |
|||
{{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 |
|||
</pre> |
</pre> |