Quadrat special primes: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: Use ALGOL 68-primes) |
(Added solution for Action!) |
||
Line 6: | Line 6: | ||
where the successor of q is the least prime, p, such that p - q is a perfect square. |
where the successor of q is the least prime, p, such that p - q is a perfect square. |
||
<br><br> |
<br><br> |
||
=={{header|Action!}}== |
|||
{{libheader|Action! Sieve of Eratosthenes}} |
|||
<lang Action!>INCLUDE "H6:SIEVE.ACT" |
|||
DEFINE MAX="15999" |
|||
DEFINE MAXSQUARES="126" |
|||
BYTE ARRAY primes(MAX+1) |
|||
INT ARRAY squares(MAXSQUARES) |
|||
PROC CalcSquares() |
|||
INT i |
|||
FOR i=1 TO MAXSQUARES |
|||
DO |
|||
squares(i-1)=i*i |
|||
OD |
|||
RETURN |
|||
INT FUNC FindNextQuadraticPrime(INT x) |
|||
INT i,next |
|||
FOR i=0 TO MAXSQUARES-1 |
|||
DO |
|||
next=x+squares(i) |
|||
IF next>MAX THEN |
|||
RETURN (-1) |
|||
FI |
|||
IF primes(next) THEN |
|||
RETURN (next) |
|||
FI |
|||
OD |
|||
RETURN (-1) |
|||
PROC Main() |
|||
INT p=[2] |
|||
Put(125) PutE() ;clear the screen |
|||
Sieve(primes,MAX+1) |
|||
CalcSquares() |
|||
WHILE p>0 |
|||
DO |
|||
PrintI(p) Put(32) |
|||
p=FindNextQuadraticPrime(p) |
|||
OD |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Quadrat_Special_Primes.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
2 3 7 11 47 83 227 263 587 911 947 983 1019 1163 1307 1451 1487 1523 1559 2459 |
|||
3359 4259 4583 5483 5519 5843 5879 6203 6779 7103 7247 7283 7607 7643 8219 8363 |
|||
10667 11243 11279 11423 12323 12647 12791 13367 13691 14591 14627 14771 15671 |
|||
</pre> |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |