I need an efficient way to compute sums of reciprocal of numbers using a computer program. Currently, I have a set of integers $\{a_{0}, a_{1}, \ldots a_{n}\}$, and I want to compute
$$\sum_{i=0}^{n} \frac{1}{a_{0}}$$ as a fraction.
I know what $n$ is. Is there a good way to do this? For example, if $n = 1$, it's just $1/a_{0}$. If $n = 2$, it's $(a_{0} + a_{1})/(a_{0} \cdot a_{1})$.
But, it gets more complicated for $n = 3$.
More specifically, I'm writing a computer program to compute the sum $S$ given by
$$S = \sum_{k=2}^{N} \frac{1}{v(k)u(k)}$$
where $v(k)$ and $u(k)$ are guaranteed to be integers. I don't think what the functions are doing actually matters for my question, but $v(k)$ represents the largest prime $p$ that does not exceed $k$, and the function $u(k)$ represents the smallest prime strictly greater than $k$. Also, $N$ is passed in as a parameter. Currently, I've stored each of the products of $v(k)u(k)$ in a vector.
You can store each partial sum as a fraction by using 2 vectors, or one vector of an object with 2 integers. In particular, you store the numerator and denominator, starting off with $1$ for the numerator and the first value of the denominator. Then for each next value to add, you can create the next partial sum of a numerator and denominator as follows for the $m$'th (for $m \ge 2$) term, where $n_{m - 1}$ is the latest stored numerator, $d_{m - 1}$ is the latest stored denominator and $\frac{1}{a_m}$ is the next fraction value:
$$\cfrac{n_{m - 1}}{d_{m - 1}} + \cfrac{1}{a_m} = \cfrac{a_m n_{m - 1} + d_{m - 1}}{a_m d_{m - 1}} \tag{1}\label{eq1} $$
This means the new next numerator can be stored as $n_m = a_m n_{m - 1} + d_{m - 1}$ and the new next denominator can be stored as $d_m = a_m d_{m - 1}$. To get a particular value, as I suggested in my comment to your question, you can either retrieve it from the vector(s), if they're already there, or use the last available one to calculate additional terms, potentially also adding each set of numerator / denominator values to your vector (if there is enough memory available).
This is one of the simplest ways to handle this issue. However, you may wish to optimize things like trying to find any common factors of the numerator and denominator to reduce their values as, depending on the type of integer type objects you are using & have available, how large each integral value can be and what sort of maximum size of $n$ is permitted, you can get numeric overflow. However, this is mainly a computing issue that you can determine on your own or ask elsewhere, such as an appropriate other forum on StackExchange.