How many integers appear in both of the following arithmetic progressions:

A1: 2, 9, 16,.....2+(1000-1)*7
A2: 3, 12, 21,.....3+(1000-1)*9

Since 2 appears in A1 but not in A2, it does not appear in both of the arithmetic progressions.

2 answers

A1_n= 2+(n-1)*7=7n-5
A2_k= 3+(k-1)*9=9k-6

Put A1_n=A2_k => so 9k-7n=1 and solve the Diophantine equation for n,k u can see that gcd(9,7)=1 so the solutions you want come from applying the euclidean algorithm and your numbers n,k must be less than or equal to 1000.
Calculating GCD(9,7) gives:

7 = 0*9 + 7

9 = 1*7 + 2

7 = 3*2 + 1

2 = 2*1 + 0

Then applying the Extended Euclidean Algorithm:
1 = (1 * 7) + (-3 * 2)
= (-3 * 9) + (4 * 7)
= (4 * 7) + (-3 * 9)
A particular solution is:
x0 = -3
y0 = 4
The complete solution is:
x = -3 + 7n
y = 4 - 9n