Cubic special primes: Difference between revisions

(add FreeBASIC)
Line 164:
13691 13907 14419
</pre>
 
=={{header|Nim}}==
{{trans|Go}}
<lang Nim>import math, strformat
 
func sieve(limit: Positive): seq[bool] =
# True denotes composite, false denotes prime.
result = newSeq[bool](limit + 1) # All false by default.
result[0] = true
result[1] = true
# No need to bother with even numbers over 2 for this task.
var p = 3
while true:
let p2 = p * p
if p2 > limit: break
for i in countup(p2, limit, 2 * p):
result[i] = true
while true:
inc p, 2
if not result[p]: break
 
func isCube(n: int): bool =
let s = cbrt(n.toFloat).int
result = s * s * s == n
 
let c = sieve(14999)
echo "Cubic special primes under 15_000:"
echo " Prime1 Prime2 Gap Cbrt"
var lastCubicSpecial = 3
var count = 1
echo &"{2:7} {3:7} {1:6} {1:4}"
for n in countup(5, 14999, 2):
if c[n]: continue
let gap = n - lastCubicSpecial
if gap.isCube:
let gapCbrt = cbrt(gap.toFloat).int
echo &"{lastCubicSpecial:7} {n:7} {gap:6} {gapCbrt:4}"
lastCubicSpecial = n
inc count
echo &"\n{count + 1} such primes found."</lang>
 
{{out}}
<pre>Cubic special primes under 15_000:
Prime1 Prime2 Gap Cbrt
2 3 1 1
3 11 8 2
11 19 8 2
19 83 64 4
83 1811 1728 12
1811 2027 216 6
2027 2243 216 6
2243 2251 8 2
2251 2467 216 6
2467 2531 64 4
2531 2539 8 2
2539 3539 1000 10
3539 3547 8 2
3547 4547 1000 10
4547 5059 512 8
5059 10891 5832 18
10891 12619 1728 12
12619 13619 1000 10
13619 13627 8 2
13627 13691 64 4
13691 13907 216 6
13907 14419 512 8
 
23 such primes found.</pre>
 
=={{header|Perl}}==
Anonymous user