# Ravenity of Cube Distance Numbers

## Pyth - 2119 18 bytes

I wonder if there's a trick.

l{st#mP+Q^d3s_BMSE


Test Suite.

l                   Length
{                  Uniquify
s                 Combine divisor lists
t#               Filter by if more than one element
PM             Take prime factorization of each number
+RQ          Add each num in list to input
s_BM      Each num in list and its negative (with bifurcate)
^R3   Cube each num in list
SE Inclusive unary range - [1, 2, 3,... n] to input


## Jelly, 16 bytes

ŒRḟ0*3+µÆfFœ-µQL


Takes x and n as command-line arguments, in that order. Try it online!

### How it works

ŒRḟ0*3+µÆfFœ-µQL  Main link. Arguments, x, n

ŒR                Range; yield [-x, ..., x].
ḟ0              Filter out 0.
*3            Cube each remaining integer.
+           Add n to all cubes.
Æf        Factorize each k in A.
F       Flatten the resulting, nested list.
œ-     Perform multiset difference with A.
If k in A is prime, Æf returns [k], adding on k too many to the
flat list. Multiset difference with A removes exactly one k from
the results, thus getting rid of primes.
If k is composite (or 1), it cannot appear in the primes in the
flat list, so subtracting it does nothing.
µ    Begin a new, monadic link. Argument: D (list of prime divisors)
Q   Unique; deduplicate D.
L  Compute the length of the result.


## Julia, 107 bytes

f(n,x)=endof(∪(foldl(vcat,map(k->[keys(factor(k))...],filter(i->!isprime(i),[n+z^3for z=[-x:-1;1:x]])))))


This is a function that accepts two integers and returns an integer.

Ungolfed:

function f(n, x)
# Get all cube distance numbers
cubedist = [n + z^3 for z = [-x:-1; 1:x]]

# Filter out the primes and zeros
noprimes = filter(i -> !isprime(i) && i > 0, cubedist)

# Factor each remaining number
factors = map(k -> [keys(factor(k))...], noprimes)

# Flatten the list of factors
flat = foldl(vcat, factors)

# Return the number of unique elements
return endof(∪(flat))
end