The Next Prime — Solution & Editorial
Test candidates N+1, N+2, ... for primality with √-trial division or Miller–Rabin. Prime gaps near 1012 are tiny (< 400), so few candidates are tested.
Complexity: O(gap · √N) with trial division — fast in practice