Can you find your location in $\mathbb{Z}$ using least prime factor?
Here is one way utilizing that $x,N \in \mathbb{Z}$ and $\mathrm{lpf}(1):=1$ (second part might need additional clarification by OP, but without it the function would be undefined so assuming this is a natural definition).
As mentioned in comments, we have $f(-N)=1$ and this is the only value of $x$ for which $f(x)=1$ - for all other values we have $(N+x)^2+1>1$ and so it divisible by at least one prime. So we just need to try all $|x| \leq |N|$, which takes finite amount of queries, at most $2|N|+1$.
This can be improved significantly by using the fact that upon hitting $(N+x)^2+1$ a prime, we have $f(x)=(N+x)^2+1$, and so $N=\pm\sqrt{f(x)-1}-x$. So whenever $f(x)-1$ is a square and one of two resulting $N$'s satisfies $f(-N)=1$, we can terminate. This speeds up the searching significantly for large $N$, but still needs to be combined with previous approach which guarantees it will terminate (otherwise the algorithm would rely on assumption that there are infinitely many primes of form $n^2+1$ - which is an open problem).