Our programming teacher asked us to find triple positive integers n,p,q (m=2) such that:
$p$ and $q$ divide $2n² - 1$ and $2n$ divides $p - q$
With the program below, I didn't find such an integer (I stopped the iterations at 1000000). So, I wonder if such an integer n does exist or if my program is faulty.
from sympy import isprime
def find_integers():
solutions = []
max_n = 10**6 # Upper limit for n
for n in range(1, max_n + 1):
if not isprime(2 * n ** 2 - 1):
for p in range(1, 2 * n ** 2 - 1, 2):
for q in range(1, 2 * n ** 2 - 1, 2):
if (2 * n ** 2 - 1) % p == 0 and (2 * n ** 2 - 1) % q == 0 and (p - q) % (2 * n) == 0 and p != q:
solutions.append((n, p, q))
if n % 100 == 0: # Print progress every 100 iterations
print(f"Progress: n = {n}")
return solutions
# Find the solutions
solutions = find_integers()
# Display the results
if solutions:
print("Solutions:")
for i, (n, p, q) in enumerate(solutions):
print(f"Solution {i + 1}: n = {n}, p = {p}, q = {q}")
else:
print("No solutions found.")
Addition: This question is completely resolved: In the case m=2 by Denis Shatrov in this thread and in the case m>1 by GH from MO in MO
There is no integers $n$, $p \ne q$ such that $p, q \mid 2n^2 - 1$, $p, q > 0$, $p \equiv q \pmod{2n}$. The following solution is based on the theory of generalized Pell's equation.
If $\gcd(p, q) > 1$, then $p', q' \mid 2n^2 - 1$ and $p' \equiv q' \pmod{2n}$, where $p' = \frac{p}{\gcd(p, q)}$, $q' = \frac{q}{\gcd(p, q)}$. Hence, $p$ and $q$ can be considered coprime. Hence, $pq \mid 2n^2 - 1$. Let $q = p + 2nt$. We get the equation
$$2n^2 - 1 = sp(p + 2nt)$$ $$(2n - spt)^2 - (s^2t^2 + 2s)p^2 = 2$$ This is a generalized Pell's equation. Associated Pell's equation is $$x^2 - (s^2t^2 + 2s)y^2 = 1$$ which has fundamental solution $(st^2 + 1, t)$. Solutions of the generalized Pell's equation can be bounded. See https://en.m.wikipedia.org/wiki/Pell%27s_equation, section "Generalized Pell's equation".
$$p \le \sqrt{2} \frac{\sqrt{st^2 + 1 + t\sqrt{s^2t^2 + 2s} } + 1}{2 \sqrt{s^2t^2 + 2s}} < 2$$ Hence, $p \in \{0, 1\}$. Case $p = 0$ is clearly impossible. Case $p = 1$ is impossible, because for $t > 1$ we have $(st)^2 < s^2t^2 + 2s + 2 < (st + 1)^2$. Case $t = 1$ gives equation $$(2n - sp)^2 = s^2 + 2s + 2$$ which has no solutions.