Strong and weak primes: Difference between revisions
Content added Content deleted
(add FreeBASIC) |
(Added XPL0 example.) |
||
Line 2,544: | Line 2,544: | ||
The count of the weak primes below 10,000,000 is 321,750. |
The count of the weak primes below 10,000,000 is 321,750. |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<lang XPL0>proc NumOut(Num); \Output positive integer with commas |
|||
int Num, Dig, Cnt; |
|||
[Cnt:= [0]; |
|||
Num:= Num/10; |
|||
Dig:= rem(0); |
|||
Cnt(0):= Cnt(0)+1; |
|||
if Num then NumOut(Num); |
|||
Cnt(0):= Cnt(0)-1; |
|||
ChOut(0, Dig+^0); |
|||
if rem(Cnt(0)/3)=0 & Cnt(0) then ChOut(0, ^,); |
|||
]; |
|||
func IsPrime(N); \Return 'true' if odd N > 2 is prime |
|||
int N, I; |
|||
[for I:= 3 to sqrt(N) do |
|||
[if rem(N/I) = 0 then return false; |
|||
I:= I+1; |
|||
]; |
|||
return true; |
|||
]; |
|||
int StrongCnt, WeakCnt, StrongCnt0, WeakCnt0, Strongs(36), Weaks(37); |
|||
int N, P0, P1, P2, T; |
|||
[StrongCnt:= 0; WeakCnt:= 1; |
|||
Weaks(0):= 3; |
|||
N:= 7; P1:= 3; P2:= 5; \handles unique case where (2+5)/2 = 3.5 |
|||
repeat if IsPrime(N) then |
|||
[P0:= P1; P1:= P2; P2:= N; |
|||
T:= (P0+P2)/2; |
|||
if P1 > T then |
|||
[if StrongCnt < 36 then Strongs(StrongCnt):= P1; |
|||
StrongCnt:= StrongCnt+1; |
|||
]; |
|||
if P1 < T then |
|||
[if WeakCnt < 37 then Weaks(WeakCnt):= P1; |
|||
WeakCnt:= WeakCnt+1; |
|||
]; |
|||
]; |
|||
if P1 < 1_000_000 then |
|||
[StrongCnt0:= StrongCnt; WeakCnt0:= WeakCnt]; |
|||
N:= N+2; |
|||
until P1 >= 10_000_000; |
|||
Text(0, "First 36 strong primes:^M^J"); |
|||
for N:= 0 to 36-1 do |
|||
[NumOut(Strongs(N)); ChOut(0, ^ )]; |
|||
Text(0, "^M^JStrong primes below 1,000,000: "); |
|||
NumOut(StrongCnt0); |
|||
Text(0, "^M^JStrong primes below 10,000,000: "); |
|||
NumOut(StrongCnt); |
|||
Text(0, "^M^JFirst 37 weak primes:^M^J"); |
|||
for N:= 0 to 37-1 do |
|||
[NumOut(Weaks(N)); ChOut(0, ^ )]; |
|||
Text(0, "^M^JWeak primes below 1,000,000: "); |
|||
NumOut(WeakCnt0); |
|||
Text(0, "^M^JWeak primes below 10,000,000: "); |
|||
NumOut(WeakCnt); |
|||
CrLf(0); |
|||
]</lang> |
|||
{{out}} |
|||
<pre> |
|||
First 36 strong primes: |
|||
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 |
|||
Strong primes below 1,000,000: 37,723 |
|||
Strong primes below 10,000,000: 320,991 |
|||
First 37 weak primes: |
|||
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 |
|||
Weak primes below 1,000,000: 37,780 |
|||
Weak primes below 10,000,000: 321,751 |
|||
</pre> |
</pre> |
||