Efficient Equation for Counting Even Numbers from 1 to n

  • Thread starter Thread starter Genericcoder
  • Start date Start date
  • Tags Tags
    Count even
Click For Summary
The discussion focuses on a proposed equation for counting even numbers from 1 to n, presented by a novice in number theory. The equation is derived from analyzing the structure of odd numbers and their relationship to even numbers. A more efficient formula for calculating the sum of even numbers is introduced, which simplifies the original equation using known mathematical principles. The simplified formula is expressed as n(n+2)/4, demonstrating its equivalence to the original approach. The exchange highlights the importance of mathematical efficiency and clarity in problem-solving.
Genericcoder
Messages
130
Reaction score
0
Hi guys,

I am noobie in number theory so if something exists better than this equation I did please don't bash me this is my first equation.

Today I was thinking of a way to count all even from 1 to n,so this way I thought about is like this.

Let me first write the equation,then I will explain the logic.


iNumber = ((iNumber + 1) * (iNumber / 2)) - (((iNumber + 1) * (iNumber / 2) - (iNumber / 2)) / 2)


Okay let me explain how I got this logic,so let's pick odd numbers from 1 to 10 and see how they form.
1 = 0 + 1;
3 = 2 + 1;
5 = 4 + 1;
7 = 6 + 1;
9 = 8 + 1;

So here we have 5 ones,so for example if we removed those ones from the a equation that you add 1 to 10 from it will be like this;

Normal numbers which you added 1 to 10 ->

1 + 2 + 2 + 1 + 4 + 4 + 1 + 6 + 6 + 1 + 8 + 8 + 1 + 10 -
1 + 1 + 1 + 1 + 1,so the numbers now become

0 + 2 + 2 + 4 + 4 + 6 + 6 + 8 + 8 + 10 = 50,but that's 2x,so if we got that number and divide by 2 it will be 25,thats how much odds add up,so if we got the total numbers from 1 to 10 and minus 25 we should get the even number we want;

So let's put that in the equation and see if its right;

((11) * (5)) - (((11) * (5) - (5)) / 2) = 55 - 25 = 30;

2 + 4 + 6 + 8 + 10 = 30;

So the equation is right I am sure this has been done by another mathmetician,but its good to think about it the logic of it is great.
 
Physics news on Phys.org
Hi, genericcoder,
I'll try to illustrate how your formula connects with other formulas known to mathematicians; in other words, how to prove (and simplify) your formula, if this is of any use to you.

A formula well known by mathematicians (and possibly by you) is a formula for the sum of the first consecutive integers; for example, 1 + 2 + 3 + 4 + 5. The formula is\frac {k (k+1)} 2In this example, 1 + 2 + 3 + 4 + 5 = 5 * 6 / 2 = 30 / 2 = 15.

You want to calculate the sum of consecutive even numbers, such as 2 + 4 + 6 + 8 + 10, and that is twice the sum 1 + 2 + 3 + 4 + 5. So, if your number is 10, you would apply the above formula with 10/2 = 5 (which gives you 1+2+3+4+5; we did that and obtained 5*6/2 = 15) and then multiply the result by two to obtain 2+4+6+8+10 (= 15*2 = 30).

So the sum of the first even numbers can be expressed as twice the above formula, that is, k(k+1), but using a value of \displaystyle {k=\frac n 2}:\begin{align*}\frac n 2 \left( \frac n 2 + 1 \right) &= \frac {n^2} 4 + \frac n 2 = \frac{n^2 + 2n} 4 \\ &= \frac {n(n+2)} 4 & \mbox{(eq. 1)}\end{align*}
In your example, if you evaluate \displaystyle {\frac {n(n+2)} 4} with n=10, you obtain 10*12/4 = 30, as you did.

The formula you give can be simplified to this one marked as (eq. 1), with a little algebra. Your formula is\displaystyle {(n+1)\frac n 2 - \frac {(n+1)\frac n 2 - \frac n 2} 2}
Notice that the numerator of the big fraction on the right is \displaystyle (n+1)\frac n 2 - \frac n 2; in other words, (n+1)*something - something. If you have (n+1) of something, and subtract one of something, you are left with n*something. So we begin by simplifying your formula to\displaystyle {(n+1)\frac n 2 - \frac {n\frac n 2} 2}
or(n+1)\frac n 2 - \frac {n^2} 4
Expanding the parentheses on the left part, we obtain\begin{align*}& \frac {n^2} 2 + \frac n 2 - \frac {n^2} 4 \\ &= \frac {n^2} 4 + \frac n 2 \\ &= \frac {n(n+2)} 4 \end{align*}
just as we did above for (eq. 1).

Hope this helps!
 
@Dodo

Thanks a lot that makes sense,also this logic for calculating the even is more efficient than mine I made it more complex.
 
Thread 'How to define a vector field?'
Hello! In one book I saw that function ##V## of 3 variables ##V_x, V_y, V_z## (vector field in 3D) can be decomposed in a Taylor series without higher-order terms (partial derivative of second power and higher) at point ##(0,0,0)## such way: I think so: higher-order terms can be neglected because partial derivative of second power and higher are equal to 0. Is this true? And how to define vector field correctly for this case? (In the book I found nothing and my attempt was wrong...

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
580
  • · Replies 0 ·
Replies
0
Views
780
  • · Replies 21 ·
Replies
21
Views
1K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K