Let us call a prime \$p\$ an \$(m,k)\$-distant prime \$(m \ge 0, k \ge 1, m,k \in\mathbb{Z})\$ if there exists a power of \$k\$, say \$k^x (x \ge 0, x \in\mathbb{Z})\$, such that \$|k^x-p| = m. \$ For example, \$23\$ is a \$(9,2)\$-distant prime as \$|2^5 - 23| = 9\$. In other words, any prime which is at a distance of \$m\$ from some non-negative power of \$k\$ is an \$(m,k)\$-distant prime.
For this challenge, you can either:
- Take input three integers \$n, m, k\; (n,k \ge1, m \ge0)\$ and print the \$n^{th}\$ \$(m,k)\$-distant prime. You do not need to handle inputs where answer does not exist. You can take \$n\$ as zero-indexed if you want.
- Take \$n, m, k\$ as input and print the first \$n\$ \$(m,k)\$-distant primes.
- Or, take only \$m\$ and \$k\$ as input and print all \$(m,k)\$-distant primes. It is fine if your program runs infinitely and does not terminate if there aren't any \$(m,k)\$-distant primes, or all such primes have already been printed.
Examples
m,k -> (m,k)-distant primes
1,1 -> 2
0,2 -> 2
1,2 -> 2, 3, 5, 7, 17, 31, 127, 257, 8191, 65537, 131071, 524287, ...
2,2 -> 2, 3
2,3 -> 3, 5, 7, 11, 29, 79, 83, 241, 727, 6563, 19681, 59051
3,2 -> 5, 7, 11, 13, 19, 29, 61, 67, 131, 509, 1021, 4093, 4099, 16381, 32771, 65539, 262147, ...
20,2 -> None
33,6 -> 3
37,2 -> 41, 53, 101, 293, 1061, 2011, 4133, 16421, ...
20,3 -> 7, 23, 29, 47, 61, 101, 223, 263, 709, 2207, 6581, 59029, 59069, 177127, 177167
20,7 -> 29, 2381, 16787
110,89 -> 199, 705079
Rules
- Standard loopholes are forbidden.
- You may choose to write functions instead of programs.
- This is code-golf, so the shortest code (in bytes) wins.