Cubic special primes: Difference between revisions
Content added Content deleted
Catskill549 (talk | contribs) (added AWK) |
|||
Line 7: | Line 7: | ||
<br><br> |
<br><br> |
||
=={{header|AWK}}== |
|||
<lang AWK> |
|||
# syntax: GAWK -f CUBIC_SPECIAL_PRIMES.AWK |
|||
# converted from FreeBASIC |
|||
BEGIN { |
|||
start = p = 2 |
|||
stop = 15000 |
|||
n = 1 |
|||
printf("%5d ",p) |
|||
count = 1 |
|||
do { |
|||
if (is_prime(p + n^3)) { |
|||
p += n^3 |
|||
n = 1 |
|||
printf("%5d%1s",p,++count%10?"":"\n") |
|||
} |
|||
else { |
|||
n++ |
|||
} |
|||
} while (p + n^3 <= stop) |
|||
printf("\nCubic special primes %d-%d: %d\n",start,stop,count) |
|||
exit(0) |
|||
} |
|||
function is_prime(x, i) { |
|||
if (x <= 1) { |
|||
return(0) |
|||
} |
|||
for (i=2; i<=int(sqrt(x)); i++) { |
|||
if (x % i == 0) { |
|||
return(0) |
|||
} |
|||
} |
|||
return(1) |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
2 3 11 19 83 1811 2027 2243 2251 2467 |
|||
2531 2539 3539 3547 4547 5059 10891 12619 13619 13627 |
|||
13691 13907 14419 |
|||
Cubic special primes 2-15000: 23 |
|||
</pre> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
<lang fsharp> |
<lang fsharp> |