Safe primes and unsafe primes: Difference between revisions

no edit summary
m (changed the category name)
No edit summary
Line 642:
</pre>
 
 
=={{Maple}}==
<lang|Maple>showSafePrimes := proc(n::posint)
local prime_list, k;
prime_list := [7];
for k to n - 1 do
prime_list := [op(prime_list), NumberTheory:-NextSafePrime(prime_list[-1])];
end do;
return prime_list;
end proc;
 
countSafePrimes := proc(n::posint)
local counts, prime;
counts := 1; prime := 7;
while prime < n do prime := NumberTheory:-NextSafePrime(prime);
counts := counts + 1;
end do;
return counts;
end proc;
 
countUnsafePrimes := proc(n::posint)
local safe_counts, total;
safe_counts := countSafePrimes(n);
total := NumberTheory:-PrimeCounting(n);
return total - safe_counts;
end proc;
 
showSafePrimes(35);
showSafePrimes(40);
countSafePrimes(1000000);
countSafePrimes(10000000);
countUnsafePrimes(1000000);
countUnsafePrimes(10000000);<\lang>
{{out}}
<pre>[5, 7, 11, 23, 47, 59, 83, 107, 167, 179, 227, 263, 347, 359, 383, 467, 479, 503, 563, 587, 719, 839, 863, 887, 983, 1019, 1187, 1283, 1307, 1319, 1367, 1439, 1487, 1523, 1619]
[5, 7, 11, 23, 47, 59, 83, 107, 167, 179, 227, 263, 347, 359, 383, 467, 479, 503, 563, 587, 719, 839, 863, 887, 983, 1019, 1187, 1283, 1307, 1319, 1367, 1439, 1487, 1523, 1619, 1823, 1907, 2027, 2039, 2063]
4325
30658
74173
633921<\pre>
=={{header|Pascal}}==
Using unit mp_prime of Wolfgang Erhardt, of which I use two sieve, to simplify things.
Anonymous user