We want the smallest x such that count(x) ≥ n. This is a binary search problem: search over possible values of x from 1 to n × min(a, b).
For each mid, compute count(mid). If count(mid) < n, search right. If count(mid) ≥ n, search left.
The answer is the smallest x where count(x) ≥ n. Return x mod 10^9 + 7.