Try reducing computation by finding a closed form instead of writing a loop. Here, the closed form is f(n) = n*(n+1) (e.g. f(100) = 100*101 = 10100):
f(n) = n*(n+1)
f(100) = 100*101 = 10100
f(n) = S[1..n] 2*i definition
= 2 * S[1..n] i pull out the coefficient
= 2 * n*(n+1)/2 by triangular number formula
= n*(n+1) cancel the twos
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.