Formula to find the first intersection of two arithmetic progressions Formula to find the first intersection of two arithmetic progressions
I am not good in math, but I need to determine if two generic arithmetic progressions have an intersection point and, in that case, find the first intersection. I've searched the web and found some solutions, but I couldn't understand them.
Is it possible to have a simple formula or algorithm that finds the first intersection point of two arithmetic progressions?
Example 1:
$$
A_n = A_1 + (n - 1)d \\
AP1: A_1 = 1, d = 14 \Rightarrow \{1, 15, 29, 43, \dotsc \} \\
AP2: A_1 = 8, d = 21 \Rightarrow \{8, 29, 50, 71, \dotsc \} \\
$$
Result: First intersection point on $A_n = 29$
Example 2:
$$
A_n = A_1 + (n - 1)d \\
AP1: A_1 = 1, d = 14 \Rightarrow \{1, 15, 29, 43, \dotsc \} \\
AP2: A_1 = 8, d = 28 \Rightarrow \{8, 36, 64, 92, \dotsc \}
$$
Result: Does not have an intersection point
The reason I need this is because I am developing a calendar (like Google Calendar) but where it is not allowed to create two event series that intersect each other. I've posted a similar question here.

Let the two series be $ a[n] = p + nq $ and $ b[n] = r + ns $
Assuming it does intersect, then
$ a[x] = b[y] \implies p + xq = r + ys $
It looks daunting with so many variables, but in fact $ p, q, r, s $ are all known, so not too bad. Next we rearrange 
$ p - r = ys - xq $. By the extended euclidean algorithm, we know we can find $ x $ and $ y $ such that $ ys - xq = gcd(s, q) $. 
So the two series intersect if and only if $ p - r $ is a multiple of $ gcd(s, q) $. 
To code the algorithm, just compute the gcd and do a trial division.
