# Find a Rocco number

## JavaScript (ES7), 55 bytes

n=>(g=k=>k>0&&n%--k?g(k):k==1)(n=(49+n)**.5-7)|g(n+=14)


Try it online!

### How?

Given a positive integer $$\n\$$, we're looking for a prime $$\x\$$ such that $$\x(x+14)=n\$$ or $$\x(x-14)=n\$$.

$$x^2+14x-n=0\tag{1}$$ $$x^2-14x-n=0\tag{2}$$

The positive root of $$\(1)\$$ is:

$$x_0=\sqrt{49+n}-7$$

and the positive root of $$\(2)\$$ is:

$$x_1=\sqrt{49+n}+7$$

Therefore, the problem is equivalent to testing whether either $$\x_0\$$ or $$\x_1\$$ is prime.

To do that, we use the classic recursive primality test function, with an additional test to make sure that it does not loop forever if it's given an irrational number as input.

g = k =>    // k = explicit input; this is the divisor
// we assume that the implicit input n is equal to k on the initial call
k > 0 &&  // abort if k is negative, which may happen if n is irrational
n % --k ? // decrement k; if k is not a divisor of n:
g(k)    //   do a recursive call
:         // else:
k == 1  //   returns true if k is equal to 1 (n is prime)
//   or false otherwise (n is either irrational or a composite integer)


Main wrapper function:

n => g(n = (49 + n) ** .5 - 7) | g(n += 14)


## 05AB1E, 8 bytes

Returns $$\1\$$ if $$\n\$$ is a Rocco number, or $$\0\$$ otherwise.

fDŠ/α14å


Try it online!

### How?

Given a positive integer $$\n\$$, we test whether there exists a prime factor $$\p\$$ of $$\n\$$ such that:

$$\left|p-\frac{n}{p}\right|=14$$

### Commented

fDŠ/α14å  # expects a positive integer n as input       e.g. 2655
f         # push the list of unique prime factors of n  -->  2655, [ 3, 5, 59 ]
D        # duplicate it                                -->  2655, [ 3, 5, 59 ], [ 3, 5, 59 ]
Š       # moves the input n between the two lists     -->  [ 3, 5, 59 ], 2655, [ 3, 5, 59 ]
/      # divide n by each prime factor               -->  [ 3, 5, 59 ], [ 885, 531, 45 ]
α     # compute the absolute differences
# between both remaining lists                -->  [ 882, 526, 14 ]
14å  # does 14 appear in there?                    -->  1


## Perl 6, 45 28 bytes

((*+49)**.5+(7|-7)).is-prime


Try it online!

Uses Arnauld's construction, that $$\\sqrt{n+49}\pm7\$$ must be prime for $$\n\$$ to be a Rocco number.

### Explanation:

 (*+49)**.5                   # Is the sqrt of input+49
+(7|-7)            # Plus or minus 7
(                 ).is-prime  # Prime?