How to efficiently find all the integers $N$ that satisfy two mod conditions? How to efficiently find all the integers $N$ in range $0-1000$ that satisfy both conditions:
$N$ mod $7=1$$N$ mod $9=5$
Brute-forcing gives me the answer:
for n in range(500):
    if n % 7 == 1 and n % 9 == 5:
        print(n)


50, 113, 176, 239, 302, 365, 428, 491

But is there a smart way to compute all the N without brute-forcing the whole range?
edit:
if you know Python and can put the solution into an algorithm, I would really appreciate that. It would be much easier for me to understand it.
 A: Quick hint to help you get started:
$N = 1\pmod 7 \implies N=7p+1, p \in \mathbb Z $ 
$N = 5\pmod 9 \implies N=9q+5, q \in \mathbb Z $ 
Then
\begin{align}
7p+1 & = 9q+5 \\
7p - 9q &= 4
\end{align}
You should be able to see a Diophantine equation in the form $ax+by=c$, and therefore you should be able to solve using Euclid's Algorithms.
Once you find values of $p$ and $q$, simply substitute into the above equations.
There are infinitely many solutions to a Diophantine equation, but you can reject any other integer solutions after 1000.
A: Here are the two conditions written as modular equivalences:

$N \equiv 1 \bmod 7 \\ 
N\equiv 5 \bmod 9$

The first thing to note is that any solution to this $N_0$ will be repeated at $N_0 + \text{lcm}(7,9)$ $= N_0 + 63,$ since at that point the multiples of $7$ and $9$ will produce the same equivalences.
So a "fingers and toes" method here is just to observe that, firstly, if there is any solution, there has to be one in $[1,63]$, and then just to check all the values in that range for one of the equivalence constraints against the other:
$ N\equiv 5 \bmod 9 \implies N\in\{5,14,23,32,41,50,59, \ldots\}$
And checking these values $\bmod 7$ we see that $N=50$ meets the constraint $N \equiv 1 \bmod 7$ (the only solution in the base range to $63$).
So that provides enough to answer the original question, with the $63$ repeat effect.
The Chinese Remainder theorem shows that for values meeting some coprime constraints, we will get a unique answer in the $\text{lcm}$ range.
When a simple search becomes impractical, finding modular inverses of the numbers becomes a better approach; effectively solving, in this case: 
$N\equiv 5 \bmod 9 \quad \to \text{take }N=9k+5\\
9k+5 \equiv 1 \bmod 7 \\
\implies 2k \equiv 3 \bmod 7 \\
\implies 4\cdot 2k \equiv 4\cdot 3 \bmod 7 \\
\implies k\equiv 12 \equiv 5 \\
\implies N=9\cdot 5 + 5 =50$ 
here the modular inverse step has (slightly awkwardly) been made apparent in $2^{-1}\equiv 4 \bmod 7$, and this value can in general be found through the extended Euclidean algorithm.
