42 lines
862 B
Text
42 lines
862 B
Text
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;
|
|
]
|