Research
I know that I can use Gauss' Trick for finding the sum of consecutive numbers. n/2 * (start + end)
This is illustrated here: Sum of n consecutive numbers
Question
I am trying to find a shorter solution, (one without loops) to the algorithm below: (sorry for lack of LaTeX knowledge)
For each number from 1 to N, find the sum of (the sum the numbers from 1 to Nx)
Expanded Version:
Given N = 4
N1: [(1)] +
N2: [(1 + 2) + (1)] +
N3: [(1 + 2 + 3) + (1 + 2) + (1)] +
N4: [(1 + 2 + 3 + 4) + (1 + 2 + 3) + (1 + 2) + (1)]
Using Gauss' Trick
Given N = 4
N1: [1/2 * (1 + 1)] +
N2: [2/2 * (1 + 2)] +
N3: [3/2 * (1 + 3)] +
N4: [4/2 * (1 + 4)]
Looking for a "Double Guass' Trick"
So, is there a mathematical way to calculate this "second level" approximation without needing to loop through 1-N?
Nx,xis the iteration number ofN. I am trying to find a summation inside of a summation. I am not sure how to word or write the formula for this, but I feel like theExpanded Versionof my question illustrates the steps which should help you extract the meaning. – Tim Feb 13 '21 at 23:18sum(i=1, N) i– Tim Feb 13 '21 at 23:23