What is a good way to determine the highest power of of prime number $p$ among $k$ consecutive positive integers $n$ to $n+k$?
For example:
consecutive integers $\{12,13,14,15,16,17,18,19\}$
highest power of $2$: $4$ at $16$
highest power of $3$: $2$ at $18$
You can try with a simple recursive algorithm: once you know that $p$ divides one of the numbers you immediately know which numbers are divided by $p$. If you discard the other numbers you can then iterate this process until you are left with only one number, so keep dividing it by $p$ until it is not divisible by it anymore. Note that this doesn't assume $p$ to be prime.
Here's a quick and dirty Python script implementing this algorithm. It can likely be improved, but so far it seems to work well enough.
And here's a simple benchmark:
Remark: I think that the main bottleneck of the above code is the use of lists: for $k = 10^9$ this consumes way too much memory to be usable on my system. I don't know if there is a clean way to avoid them, though.
Update: A more efficient way is to recursively enumerate, starting at $n$, the smallest numbers divisible by the successive powers of $p$, stopping as soon as we reach $n+k$. Mathematically this is fairly easy: if $d$ and $m$ are two given positive integers such that $d \nmid m$, then $$ m + d - (m \mod d) $$ is the first number after $m$ divisible by $d$.
Here's a Python script implementing this algorithm -- note that I (ab)used generators to simplify the book-keeping and to split the code in small, easily testable pieces.
I'm not sure about how to compute its complexity, but this piece of code is definitely more efficient than the previous one (both time and space wise).