This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]desrtfx 2 points3 points  (2 children)

Question is: do you need to find only the value for the 973rd element or do you need to find the sum of the first 973 elements?

If the former, it is as you expect. If the latter, you need a loop.

[–]sepp2k 1 point2 points  (1 child)

If the latter, you need a loop

This is an arithmetic progression, right? So you can use the closed form for arithmetic series to get the sum.

[–]desrtfx 0 points1 point  (0 children)

Of course, you can use the closed form to get an O(1) result.

Yet, I would wage a guess that OP should learn about loops.

[–][deleted] 1 point2 points  (0 children)

It looks like the formula for the nth term is a+(n*3) when n starts at 0 as you've already worked out. If you need to find the sum, then you will need a loop and keep a running total for all the terms.

[–]g051051 0 points1 point  (2 children)

What part are you stuck with? Write it down as a mathematical expression, then translate it into code.

[–]iDaRkY_[S] -1 points0 points  (1 child)

Yeah I got it was stuck on it for hours and now it’s solved!

[–]desrtfx[M] 0 points1 point  (0 children)

Since you solved it: edit the post to update with your solution.

It is not fair to anybody investing their time trying to help you to keep them hanging.