Hi guys,(adsbygoogle = window.adsbygoogle || []).push({});

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 lets 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 thats 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 lets 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 Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Count all even from 1 to n

**Physics Forums | Science Articles, Homework Help, Discussion**