25 lines
720 B
Text
25 lines
720 B
Text
go =>
|
|
println(findall(P, (member(P,primes(500)),long_prime(P)))),
|
|
nl,
|
|
println("Number of long primes up to limit are:"),
|
|
foreach(Limit in [500,1_000,2_000,4_000,8_000,16_000,32_000,64_000])
|
|
printf(" <= %5d: %4d\n", Limit, count_all( (member(P,primes(Limit)), long_prime(P)) ))
|
|
end,
|
|
nl.
|
|
|
|
long_prime(P) =>
|
|
get_rep_len(P) == (P-1).
|
|
|
|
%
|
|
% Get the length of the repeating cycle for 1/n
|
|
%
|
|
get_rep_len(I) = Len =>
|
|
FoundRemainders = {0 : _K in 1..I+1},
|
|
Value = 1,
|
|
Position = 1,
|
|
while (FoundRemainders[Value+1] == 0, Value != 0)
|
|
FoundRemainders[Value+1] := Position,
|
|
Value := (Value*10) mod I,
|
|
Position := Position+1
|
|
end,
|
|
Len = Position-FoundRemainders[Value+1].
|