RosettaCodeData/Task/Strong-and-weak-primes/Maple/strong-and-weak-primes.maple
2023-07-01 13:44:08 -04:00

44 lines
897 B
Text

isStrong := proc(n::posint) local holder;
holder := false;
if isprime(n) and 1/2*prevprime(n) + 1/2*nextprime(n) < n then
holder := true;
end if;
return holder;
end proc:
isWeak := proc(n::posint) local holder;
holder := false;
if isprime(n) and n < 1/2*prevprime(n) + 1/2*nextprime(n) then
holder := true;
end if;
return holder;
end proc
findStrong := proc(n::posint) local count, list, k;
count := 0; list := [];
for k from 3 while count < n do
if isStrong(k) then count := count + 1;
list := [op(list), k];
end if;
end do;
return list;
end proc:
findWeak := proc(n::posint) local count, list, k;
count := 0;
list := [];
for k from 3 while count < n do
if isWeak(k) then
count := count + 1;
list := [op(list), k];
end if;
end do;
return list;
end proc:
findStrong(36)
findWeak(37)
countStrong(1000000)
countStrong(10000000)
countWeak(1000000)
countWeak(10000000)