Efficient Equation for Counting Even Numbers from 1 to n

  • Thread starter Genericcoder
  • Start date
  • Tags
    Count even
In summary, the equation is as follows: iNumber = ((iNumber + 1) * (iNumber / 2)) - (((iNumber + 1) * (iNumber / 2) - (iNumber / 2)) / 2) if you have odd numbers from 1-10 and want the even number, you do the following:((11) * (5)) - (((11) * (5) - (5)) / 2) = 55 - 25 = 302 + 4 + 6 + 8 + 10 = 30
  • #1
Genericcoder
131
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
  • #2
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[tex]\frac {k (k+1)} 2[/tex]In 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, [itex]k(k+1)[/itex], but using a value of [itex]\displaystyle {k=\frac n 2}[/itex]:[tex]\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*}[/tex]
In your example, if you evaluate [itex]\displaystyle {\frac {n(n+2)} 4}[/itex] with [itex]n=10[/itex], 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[tex]\displaystyle {(n+1)\frac n 2 - \frac {(n+1)\frac n 2 - \frac n 2} 2}[/tex]
Notice that the numerator of the big fraction on the right is [itex]\displaystyle (n+1)\frac n 2 - \frac n 2[/itex]; 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[tex]\displaystyle {(n+1)\frac n 2 - \frac {n\frac n 2} 2}[/tex]
or[tex](n+1)\frac n 2 - \frac {n^2} 4[/tex]
Expanding the parentheses on the left part, we obtain[tex]\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*}[/tex]
just as we did above for (eq. 1).

Hope this helps!
 
  • #3
@Dodo

Thanks a lot that makes sense,also this logic for calculating the even is more efficient than mine I made it more complex.
 

1. What is the purpose of counting all even numbers from 1 to n?

The purpose of counting all even numbers from 1 to n is to determine the total number of even numbers within a given range. This information can be useful in various mathematical and scientific applications.

2. How do you count all even numbers from 1 to n?

To count all even numbers from 1 to n, start by identifying the first even number in the range (2). Then, continue adding 2 to the previous even number until you reach n. The total number of even numbers in this range will be (n/2) if n is even, or ((n+1)/2) if n is odd.

3. Can counting all even numbers from 1 to n help in finding the sum of these numbers?

Yes, counting all even numbers from 1 to n can help in finding the sum of these numbers. The sum of all even numbers from 1 to n can be calculated using the formula n*(n+2)/4. This can be useful in various mathematical and scientific calculations.

4. Is counting all even numbers from 1 to n a time-consuming task?

No, counting all even numbers from 1 to n is not a time-consuming task. It follows a simple pattern and can be done quickly using mental math or with the help of a calculator.

5. How is counting all even numbers from 1 to n related to the concept of even numbers?

Counting all even numbers from 1 to n is directly related to the concept of even numbers. It helps to understand the properties of even numbers and their distribution within a given range. Additionally, it can also be used to identify patterns and relationships between even numbers.

Similar threads

  • Linear and Abstract Algebra
Replies
2
Views
299
  • Linear and Abstract Algebra
Replies
8
Views
771
  • Linear and Abstract Algebra
Replies
2
Views
866
  • Linear and Abstract Algebra
Replies
1
Views
717
  • Linear and Abstract Algebra
Replies
1
Views
862
  • Linear and Abstract Algebra
Replies
11
Views
1K
  • Linear and Abstract Algebra
Replies
4
Views
833
Replies
3
Views
379
  • Nuclear Engineering
Replies
7
Views
1K
  • General Math
Replies
24
Views
2K
Back
Top