# Upper bounds for the $n$-th record gap between primes in a residue class

(Following question 2269073. See also respective lower bounds.)

Let $$q$$ and $$r$$ be coprime integers, $$1\le r < q$$, and consider the arithmetic progression $$r, \ r+q, \ r+2q, \ r+3q, \ldots \tag{P}$$

Dirichlet proved that there are infinitely many primes in progression (P).

Let $$R(n,q,r)$$ be the $$n$$th record gap between primes in progression (P). For example, with $$q=6$$ and $$r=1$$, we have $$R(n,6,1)=\mbox{A268925}(n)$$; see http://oeis.org/A268925.

Conjecture (see arXiv:1709.05508): Almost all record gaps satisfy $$R(n,q,r) < \varphi(q) n^2 + (n+2)q\log^2 q. \tag{1}$$

Question 1: Find a counterexample to inequality $$(1)$$. (You will likely need to write a program and run it long enough. No counterexamples exist for $$r and $$n\le14$$.)

For comparison, here is a tighter conjectural bound (also for almost all record gaps): $$R(n,q,r) < \varphi(q) n^2 + (n+2)\varphi(q)\log^2 q. \tag{2}$$ Here $$\varphi(q)$$ is Euler's totient function.

A few counterexamples to $$(2)$$ are known; e.g. for $$q=20$$, $$r=17$$.

Question 2: Find more counterexamples to inequality $$(2)$$.

Take $$q=23$$ and $$r=4$$. The record gaps between primes $$p\equiv 4$$ (mod $$23$$) are $$138 = 211 - 73,$$ $$322 = 809 - 487,$$ $$1150 = 4259 - 3109,$$ $$1380 = 144973 -143593,$$ $$2070 = 459337 - 457267 \ldots$$
The 5th record gap occurring between primes 457267 and 459337 in residue class 4 (mod 23) is $$2070 = 459337-457267 > 22\cdot5^2 + (5+2)\cdot22\cdot(\log23)^2 \approx2064.02.$$ This is a counterexample to inequality $$(2)$$ for $$n=5$$. (This only answers question 2.)