Strong and weak primes: Difference between revisions

no edit summary
No edit summary
Line 460:
There are 321750 weak primes below ten million.
</pre>
=={{header|Maple}}==
<lang maple>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)</lang>
{{Out}}
<pre>[11, 17, 29, 37, 41, 59, 67, 71, 79, 97, 101, 107, 127, 137, 149, 163, 179, 191, 197, 223, 227, 239, 251, 269, 277, 281, 307, 311, 331, 347, 367, 379, 397, 419, 431, 439]
[3, 7, 13, 19, 23, 31, 43, 47, 61, 73, 83, 89, 103, 109, 113, 131, 139, 151, 167, 181, 193, 199, 229, 233, 241, 271, 283, 293, 313, 317, 337, 349, 353, 359, 383, 389, 401]
37723
320991
37780
321750</pre>
 
=={{header|Pascal}}==
Anonymous user