login
Least nonnegative integer k such that n + k^3 is prime, or -1 if no such k exists.
1

%I #8 Dec 30 2017 10:06:34

%S 1,0,0,1,0,1,0,-1,2,1,0,1,0,3,2,1,0,1,0,3,2,1,0,5,4,3,-1,1,0,1,0,3,2,

%T 3,2,1,0,5,2,1,0,1,0,3,2,1,0,5,4,11,2,1,0,5,6,3,8,1,0,1,0,3,2,-1,2,1,

%U 0,5,10,1,0,1,0,3,2,3,6,1,0,3,2,1,0,13,4,3,4,1,0,7,6,9,2,9,2,1,0,5,2,1

%N Least nonnegative integer k such that n + k^3 is prime, or -1 if no such k exists.

%C For n = 2^3, 3^3, 4^3,...., a(n) = -1 since, say, 2^3 + k^3 cannot be prime for nonnegative k (it can be factored by the sum of cubes formula).

%C a(n) = 0 if and only if n is prime. - _Iain Fox_, Dec 29 2017

%H Iain Fox, <a href="/A072943/b072943.txt">Table of n, a(n) for n = 1..10000</a>

%e a(9) = 2 since k = 2 is the least nonnegative integer such that 9 + k^3 is prime.

%t Array[Which[PrimeQ@ #, 0, And[# > 1, IntegerQ@ Power[#, 1/3]], -1, True, Block[{k = 1}, While[! PrimeQ[# + k^3], k++]; k]] &, 100] (* _Michael De Vlieger_, Dec 30 2017 *)

%o (PARI) a(n) = if(round(n^(1/3))^3 == n && n!=1, return(-1)); for(k=0, +oo, if(isprime(n + k^3), return(k))) \\ _Iain Fox_, Dec 29 2017

%K sign

%O 1,9

%A _Joseph L. Pe_, Aug 14 2002