26 lines
610 B
Plaintext
26 lines
610 B
Plaintext
|
|
def main with input n output result as
|
||
|
|
if (n % 2) == 0 then result := 1
|
||
|
|
else (
|
||
|
|
result := 0;
|
||
|
|
s := 0;
|
||
|
|
while (0 == ((n - 1) / (2 ^ s)) % 2) do (
|
||
|
|
s := s + 1
|
||
|
|
);
|
||
|
|
d := ((n - 1) / 2 ^ s);
|
||
|
|
for (i := 20, i > 0, i := i - 1) do (
|
||
|
|
a := rand(n - 4) + 2;
|
||
|
|
x := powmod(a, d, n);
|
||
|
|
y := 0;
|
||
|
|
for (j := 0, j < s, j := j+1) do (
|
||
|
|
y := powmod(x, 2, n);
|
||
|
|
if (y == 1 && (not x == 1) && (not x == n - 1)) then
|
||
|
|
result := 1;
|
||
|
|
else
|
||
|
|
skip;
|
||
|
|
x := y;
|
||
|
|
);
|
||
|
|
if not y == 1 then result := 1;
|
||
|
|
else skip;
|
||
|
|
)
|
||
|
|
)
|