# Exact Sum of 1/2 to 1/n [duplicate]

Consider the sequence 1/2, 1/3 + 1/2, 1/4 + 1/3 + 1/2, and so on. In mathematical symbols, this is

$$S(n)=\sum_{m=2}^{n+1}\frac{1}{m}$$

where S is the function that makes the sequence.

Outputting this sequence as a fraction would not be complicated. To add depth to the challenge, you must output as a repeating decimal.

To represent non-repeating decimals, simply output the decimal. To represent repeating decimals, put an R before the repeating part.

For example, 1/7 can be represented by 0.R142857, and 11/9 by 1.R2

Your task is to output the nth number in this sequence, and because this is code-golf the shortest program will win.

• I strongly feel that this is a duplicate of codegolf.stackexchange.com/q/168700/78410 and codegolf.stackexchange.com/q/89215/78410. OP contains a slight variation of both (sum formula is offset by one, and notation for repeating decimal is different), but both changes are minor compared to the core of the tasks. Jan 11 at 0:27
• Need it be simpliest?
– l4m2
Jan 11 at 0:45
• @I4m2 The decimals do not need to be in simplest form. Jan 11 at 0:47
• @Bubbler I'm voting to close this as a duplicate; I think that's the best idea for this question. Jan 11 at 0:50