Cubic special primes
Cubic special primes is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
- Task
n is smallest prime such that the difference of successive terms are the smallest cubics of positive integers,
where n < 15000.
Raku
A two character difference from the Quadrat Special Primes entry. (And it could have been one.) <lang perl6>my @sqp = 2, -> $previous {
my $next; for (1..∞).map: *³ { $next = $previous + $_; last if $next.is-prime; } $next
} … *;
say "{+$_} matching numbers:\n", $_».fmt('%5d').batch(7).join: "\n" given
@sqp[^(@sqp.first: * > 15000, :k)];</lang>
- Output:
23 matching numbers: 2 3 11 19 83 1811 2027 2243 2251 2467 2531 2539 3539 3547 4547 5059 10891 12619 13619 13627 13691 13907 14419
Ring
<lang ring> load "stdlib.ring"
see "working..." + nl
Primes = [] limit1 = 50 oldPrime = 2 add(Primes,2)
for n = 1 to limit1
nextPrime = oldPrime + pow(n,3) if isprime(nextPrime) n = 1 add(Primes,nextPrime) oldPrime = nextPrime else nextPrime = nextPrime - oldPrime ok
next
see "prime1 prime2 Gap" + nl for n = 1 to Len(Primes)-1
diff = Primes[n+1] - Primes[n] see ""+ Primes[n] + " " + Primes[n+1] + " " + diff + nl
next
see "Found " + Len(Primes) + " of the smallest primes < 15,000 such that the difference of successive terma are the smallest cubic numbers" + nl
see "done..." + nl </lang>
- Output:
working... prime1 prime2 Gap 2 3 1 3 11 8 11 19 8 19 83 64 83 1811 1728 1811 2027 216 2027 2243 216 2243 2251 8 2251 2467 216 2467 2531 64 2531 2539 8 2539 3539 1000 3539 3547 8 3547 4547 1000 4547 5059 512 5059 10891 5832 10891 12619 1728 12619 13619 1000 13619 13627 8 13627 13691 64 13691 13907 216 13907 14419 512 Found 23 of the smallest primes < 15,000 such that the difference of successive terma are the smallest cubic numbers done...