On finding the $n$-th term of an arithmetic progression Given the common difference $d$, and first term $a$ (say). It is very easy to find the $n$th  term of an arithmetic progression.
My question is if we are given two common differences say $d_1$ and $d_2$, and the first term, how could we compute all possible (unique) values for the $n$th term.
For example: 
If $a = 5, n  = 3, d_1 = 1, d_2 = 2$. 
The possible sequences(using $d_1$ and $d_2$) are:
$$ \{5,6,7\}
\{5,6,8\}
\{5,7,8\}
\{5,7,9\} $$
Thus the possible (unique) answer for the $n$-th term are $\{7,8,9\}$
My attempt: 
I am am able to solve this problem using a computer by a recursive routine with exponential complexity. Is there is any mathematical approach (preferably closed form) to solve this?
 A: With out the loss of generality let us assume $d_2>d_1$. From this we see that $a+(n-1)d_1\leq a_n \leq a+(n-1)d_2$ ($a_n$ is the $n$th term). The question then becomes what values between $a+(n-1)d_1$ and $a+(n-1)d_2$ can also be achieved?
It turns out, the intermediate terms are irrelevant, we only care about how many times $d_1$ and $d_2$ are used in arriving at $a_n$. For the sake of the example say the sequence is $a,a+d_1,(a+d_1)+d_2,(a+d_1+d_2)+d_1=a_n$ so $a_n=a+2d_1+d_2$ since addition is commutative ($a,a+d_2,(a+d_2)+d_1,(a+d_2+d_1)+d_1=a_n$ has the same result). 
Note also that the sum of the coefficients on $d_1$ and $d_2$ is $n-1$, which the number of times an addition is made in an arithmetic sequence (the formula for the $n$th term is $a+(n-1)d$)
Note, finally, that every unique set of non-negative, integer coefficients $s,t$ with $s+t=n-1$, produces a unique value for $sd_1+td_2$.
So all unique $a_n$ can be described by the simple equations $a_n=a+sd_1+td_2$ and $s+t=n-1$
For your program you can use a simple for-next loop from $s=0$ to $n-1$ and have it calculate $a+sd_1+(n-1-s)d_2$. You could also calculate those values by hand if you feel so inclined.
A: At each step you can add $d_1$ or $d_2$.  
Thus $x_n=a+d_1 k+d_2(n-1-k)$ for some $k\in\{0,1,\dots,n-1\}$
Or equivalently, $x_n=a+d_2(n-1)+(d_1-d_2)k$ for some $k\in\{0,1,\dots,n-1\}$.
This should give you your possible values efficiently. 
A: The general term as ususal was $$t_n=t_1+(n-1)d=t_1+\sum_{k=1}^{n-1}d$$ But now it would be the set:

$$\large t_n\in\{t_1+\alpha_1d_1+\alpha_2d_2\mid \alpha_1+\alpha_2=n-1\}$$

