Calculate the sum of all numbers. Calculate the sum of all numbers Sum of numbers from t 0 to 100

I was lazy. To keep the children busy for a long time, and to take a nap himself, he asked them to add the numbers from 1 to 100.

Gauss answered quickly: 5050. So fast? The teacher did not believe it, but the young genius was right. Adding all the numbers from 1 to 100 is for wimps! Gauss found the formula:

$$ \ sum_ (1) ^ (n) = \ frac (n (n + 1)) (2) $$

$$ \ sum_ (1) ^ (100) = \ frac (100 (100 + 1)) (2) = 50 \ cdot 101 = 5050 $$

How did he do it? Let's try to figure it out using the example of the amount from 1 to 10.

Method one: split numbers into pairs

Let's write the numbers from 1 to 10 as a matrix with two rows and five columns:

$$ \ left (\ begin (array) (c) 1 & 2 & 3 & 4 & 5 \\ 10 & 9 & 8 & 7 & 6 \ end (array) \ right) $$

Interestingly, the sum of each column is 11 or $ n + 1 $. And there are 5 such pairs of numbers or $ \ frac (n) (2) $. We get our formula:

$$ Number \ Columns \ cdot Sum \ Numbers \ in \ Columns = \ frac (n) (2) \ cdot (n + 1) $$

If an odd number of terms?

What if you add up the numbers from 1 to 9? We are missing one number to make five pairs, but we can take zero:

$$ \ left (\ begin (array) (c) 0 & 1 & 2 & 3 & 4 \\ 9 & 8 & 7 & 6 & 5 \ end (array) \ right) $$

The sum of the columns is now 9 or exactly $ n $. And the number of columns? There are still five columns (thanks to zero!), But now the number of columns is $ \ frac (n + 1) (2) $ (y we have $ n + 1 $ and half the number of columns).

$$ Number \ columns \ cdotSum \ numbers \ in \ columns = \ frac (n + 1) (2) \ cdot n $$

Second way: double and write on two lines

We calculate the sum of the numbers a little differently in these two cases.
Maybe there is a way to calculate the sum in the same way for an even and an odd number of terms?

Instead of making a kind of "loop" out of numbers, let's write them in two lines, while multiplying the number of numbers by two:

$$ \ left (\ begin (array) (c) 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\ 10 & 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1 \ end (array) \ right) $$

For the odd case:

$$ \ left (\ begin (array) (c) 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\ 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1 \ end (array) \ right) $$

It can be seen that in both cases the sum of the columns is $ n + 1 $, and the number of columns is $ n $.

$$ Number \ columns \ cdot Sum \ numbers \ in \ columns = n \ cdot (n + 1) $$

But we only need the sum of one row, so:

$$ \ frac (n \ cdot (n + 1)) (2) $$

Third way: make a rectangle

There is one more explanation, let's try to fold the crosses, let's say we have crosses:

It looks like just a different representation of the second way - each subsequent line of the pyramid has more crosses and fewer zeros. The number of all crosses and zeroes is the area of ​​the rectangle.

$$ Area = Height \ cdot Width = n \ cdot (n + 1) $$

But we need the sum of crosses, so:

$$ \ frac (n \ cdot (n + 1)) (2) $$

Fourth way: arithmetic mean

Known: $ Average \ Arithmetic = \ frac (Sum) (Count \ Members) $
Then: $ Sum = mean \ arithmetic \ cdot Number \ members $

We know the number of members - $ n $. How to express the arithmetic mean?

Notice the numbers are evenly distributed. For each large number, there is a small one at the other end.

1 2 3, average 2

1 2 3 4, average 2.5

In this case, the arithmetic mean is the arithmetic mean of the numbers 1 and $ n $, that is, $ Average \ arithmetic = \ frac (n + 1) (2) $

$$ Sum = \ frac (n + 1) (2) \ cdot n $$

Fifth way: integral

We all know that a definite integral calculates a sum. Let's calculate the sum from 1 to 100 by an integral? Yes, but first, let's at least find the sum from 1 to 3. Let our numbers be a function of y (x). Let's draw a picture:

The heights of the three rectangles are exactly the numbers from 1 to 3. Let's draw a straight line through the middle of the “caps”:


It would be nice to find the equation of this line. It passes through points (1.5; 1) and (2.5; 2). $ y = k \ cdot x + b $.

$$ \ begin (cases) 2.5k + b = 2 \\ 1.5k + b = 1 \ end (cases) \ Rightarrow k = 1; b = -0.5 $$

Thus, the equation of the straight line with which we can approximate our rectangles is $ y = x-0.5 $


It cuts off the yellow triangles from the rectangles, but "adds" blue ones to them from above. Yellow equals blue. First, let's make sure that using the integral leads to the Gauss formula:

$$ \ int_ (1) ^ (n + 1) (x- \ frac (1) (2)) \, dx = (\ frac (x ^ (2)) (2) - \ frac (x) (2 )) (|) ^ (n + 1) _ (1) = \ frac ((n + 1) ^ (2)) (2) - \ frac (n + 1) (2) = \ frac (n ^ ( 2) + 2n + 1-n-1) (2) = \ frac (n ^ (2) + n) (2) $$

Now let's calculate the sum from 1 to 3, by x we ​​take from 1 to 4, so that all our three rectangles fall into the integral:

$$ \ int_ (1) ^ (4) (x- \ frac (1) (2)) \, dx = (\ frac (x ^ (2)) (2) - \ frac (x) (2)) (|) ^ (4) _ (1) = \ frac (4 ^ (2)) (2) -2- (0.5-0.5) = 6 $$

$$ \ int_ (1) ^ (101) (x- \ frac (1) (2)) \, dx = (\ frac (x ^ (2)) (2) - \ frac (x) (2)) (|) ^ (101) _ (1) = \ frac (101 ^ (2)) (2) -50.5- (0.5-0.5) = 5100.5-50.5 = 5050 $$

And why is all this necessary?

$$ \ frac (n (n + 1)) (2) = \ frac (n ^ (2)) (2) + \ frac (n) (2) $$

On the first day one person came to your site, on the second day two ... Every day the number of visits increased by 1. How many visits will the site gain by the end of the 1000th day?

$$ \ frac (n (n + 1)) (2) = \ frac (n ^ (2)) (2) + \ frac (n) (2) = \ frac (1000 ^ (2)) (2) + \ frac (1000) (2) = 500000 + 500 = 500500 $$

The cycle "Entertaining Mathematics" is dedicated to children who are fond of mathematics and parents who devote time to the development of their children, "throwing" interesting and entertaining tasks and puzzles to them.

The first article in this series is devoted to the Gauss rule.

A bit of history

The famous German mathematician Karl Friedrich Gauss (1777-1855) differed from his peers from early childhood. Despite the fact that he was from a poor family, he learned to read, write, and count early enough. In his biography, there is even a mention of the fact that at the age of 4-5 years he was able to correct the error in his father's miscalculations, simply by observing him.

One of his first discoveries was made at the age of 6 in a math class. The teacher needed to captivate the children for a long time and he proposed the following problem:

Find the sum of all natural numbers from 1 to 100.

Young Gauss coped with this task quickly enough, finding an interesting pattern that became widespread and is used to this day in oral counting.

Let's try to solve this problem orally. But first, let's take the numbers from 1 to 10:

1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10

Look closely at this amount and try to guess what unusual Gauss could see? To answer, you need to have a good idea of ​​the composition of the numbers.

Gauss grouped the numbers as follows:

(1+10) + (2+9) + (3+8) + (4+7) + (5+6)

Thus, little Karl received 5 pairs of numbers, each of which individually adds up to 11. Then, to calculate the sum of natural numbers from 1 to 10, you need

Let's go back to the original problem. Gauss noticed that it was necessary to group numbers into pairs before summing, and thus invented an algorithm thanks to which you can quickly add numbers from 1 to 100:

1 + 2 + 3 + 4 + 5 + … + 48 + 49 + 50 + 51 + 52 + 53 + … + 96 + 97 + 98 + 99 + 100

    Find the number of pairs in a series of natural numbers. In this case, there are 50 of them.

    We summarize the first and last numbers of this series. In our example, these are 1 and 100. We get 101.

    We multiply the resulting sum of the first and last term in the series by the number of pairs in this series. We get 101 * 50 = 5050

Therefore, the sum of the natural numbers from 1 to 100 is 5050.

Problems for using the Gauss rule

And now we are offering you problems in which the Gauss rule is used to one degree or another. A fourth-grader is quite capable of understanding and solving these problems.

You can give the child the opportunity to reason for himself, so that he himself "invented" this rule. Or you can take it apart and see how he can apply it. Among the tasks below, there are examples in which you need to understand how to modify the Gaussian rule to apply it to a given sequence.

In any case, in order for a child to operate with this in his calculations, it is necessary to understand the Gauss algorithm, that is, the ability to split correctly into pairs and count.

Important! If a formula is memorized without understanding, it will be forgotten very quickly.

Problem 1

Find the sum of numbers:

  • 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
  • 1 + 2 + 3 + … + 14 + 15 + 16;
  • 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9;
  • 1 + 2 + 3 + 4 + 5 + … + 48 + 49 + 50 + 51 + 52 + 53 + … + 96 + 97 + 98 + 99 + 100.

Solution.

First, you can give the child the opportunity to solve the first example himself and offer to find a way in which it is easy to do this in the mind. Next, analyze this example together with the child and show how Gauss did it. It is best to write down a series for clarity and connect pairs of numbers with lines that add up to the same number. It is important that the child understands how pairs are formed - we take the smallest and largest of the remaining numbers, provided that the number of numbers in the row is even.

  • 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = (1 + 10) + (2 + 9) + (3 + 8) + (4 + 7) + (5 + 6) = (1 + 10) * 5;
  • 1 + 2 + 3 + … + 14 + 15 + 16 = (1 + 16) + (2 + 15) + (3 + 14) + (4 + 13) + (5 + 12) + (6 + 11) + (7 + 10) + (8 + 9) = (1 + 16) * 8 = 136;
  • 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = (1 + 8) + (2 + 7) + (3 + 6) + (4 + 5) + 9 = (1+ 8) * 4 + 9 = 45;
  • 1 + 2 + 3 + 4 + 5 + … + 48 + 49 + 50 + 51 + 52 + 53 + … + 96 + 97 + 98 + 99 + 100 = (1 + 100) * 50 = 5050

Task2

There are 9 weights of 1g, 2g, 3g, 4g, 5g, 6g, 7g, 8g, 9g. Is it possible to split these weights into three piles of equal weight?

Solution.

Using the Gauss rule, we find the sum of all weights:

1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = (1 + 8) * 4 + 9 = 45 (d)

So, if we can group the weights so that each pile contains weights with a total weight of 15g, then the problem is solved.

One of the options:

  • 9g, 6g
  • 8g, 7g
  • 5g, 4g, 3g, 2g, 1g

Find other possible options yourself with your child.

Pay the child's attention to the fact that when solving such problems, it is better to always start grouping with a larger weight (number).

Problem 3

Is it possible to divide the clock face with a straight line into two parts so that the sums of the numbers in each part are equal?

Solution.

To begin with, apply the Gauss rule to a series of numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12: find the sum and see if it is divisible by 2:

So you can divide. Now let's see how.

Therefore, it is necessary to draw a line on the dial so that 3 pairs fall into one half, and three into the other.

Answer: the line will run between the numbers 3 and 4, and then between the numbers 9 and 10.

Task4

Is it possible to draw two straight lines on the dial of a watch so that in each part the sum of the numbers is the same?

Solution.

To begin with, apply the Gauss rule to a series of numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12: find the sum and see if it is divisible by 3:

1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 = (1 + 12) * 6 = 78

78 is divisible by 3 without a remainder, so you can divide. Now let's see how.

According to Gauss's rule, we get 6 pairs of numbers, each of which adds up to 13:

1 and 12, 2 and 11, 3 and 10, 4 and 9, 5 and 8, 6 and 7.

Therefore, it is necessary to draw lines on the dial so that 2 pairs fall into each part.

Answer: the first line will run between the numbers 2 and 3, and then between the numbers 10 and 11; the second line is between the numbers 4 and 5, and then between 8 and 9.

Problem 5

A flock of birds is flying. There is one bird (leader) ahead, followed by two, then three, four, etc. How many birds are there in the flock, if there are 20 of them in the last row?

Solution.

We get that we need to add numbers from 1 to 20. And to calculate such a sum, you can apply the Gauss rule:

1 + 2 + 3 + 4 + 5 + … + 15 + 16 + 17 + 18 + 19 + 20 = (20 + 1) * 10 = 210.

Problem 6

How to place 45 rabbits in 9 cages so that all cages have a different number of rabbits?

Solution.

If the child decided and understood the examples from task 1 with understanding, then he immediately remembers that 45 is the sum of numbers from 1 to 9. Therefore, we plant rabbits like this:

  • the first cell is 1,
  • the second - 2,
  • third - 3,
  • eighth - 8,
  • ninth - 9.

But if the child cannot immediately figure it out, then try to push him to the idea that such problems can be solved by brute force and must start with the minimum number.

Problem 7

Calculate the sum using the Gauss trick:

  • 31 + 32 + 33 + … + 40;
  • 5 + 10 + 15 + 20 + … + 100;
  • 91 + 81 + … + 21 + 11 + 1;
  • 1 + 2 + 3 + 4 + … + 18 + 19 + 20;
  • 1 + 2 + 3 + 4 + 5 + 6;
  • 4 + 6 + 8 + 10 + 12 + 14;
  • 4 + 6 + 8 + 10 + 12;
  • 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11.

Solution.

  • 31 + 32 + 33 + … + 40 = (31 + 40) * 5 = 355;
  • 5 + 10 + 15 + 20 + … + 100 = (5 + 100) * 10 = 1050;
  • 91 + 81 + … + 21 + 11 + 1 = (91 + 1) * 5 = 460;
  • 1 + 2 + 3 + 4 + … + 18 + 19 + 20 = (1 + 20) * 10 =210;
  • 1 + 2 + 3 + 4 + 5 + 6 = (1 + 6) * 3 = 21;
  • 4 + 6 + 8 + 10 + 12 + 14 = (4 + 14) * 3 = 54;
  • 4 + 6 + 8 + 10 + 12 = (4 + 10) * 2 + 12 = 40;
  • 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 = (1 + 10) * 5 + 11 = 66.

Problem 8

There is a set of 12 weights 1g, 2g, 3g, 4g, 5g, 6g, 7g, 8g, 9g, 10g, 11g, 12g. 4 weights were removed from the set, the total mass of which is equal to one third of the total mass of the entire set of weights. Is it possible to place the remaining weights on two scales of 4 pieces on each pan so that they are in equilibrium?

Solution.

We apply the Gauss rule to find the total mass of the weights:

1 + 2 + 3 + ... + 10 + 11 + 12 = (1 + 12) * 6 = 78 (d)

We calculate the mass of the weights that were removed:

Therefore, the remaining weights (with a total mass of 78-26 = 52 g) must be placed 26 g on each pan of the balance so that they are in equilibrium.

We do not know which weights were removed, so we must consider all possible options.

Applying the Gauss rule, weights can be broken into 6 pairs of equal weight (13g each):

1d and 12d, 2d and 11d, 3d and 10, 4d and 9d, 5d and 8d, 6d and 7d.

Then the best option is when, when removing 4 weights, two pairs from the above are removed. In this case, we will have 4 pairs: 2 pairs on one scale and 2 pairs on the other.

The worst case scenario is when 4 removed weights break 4 pairs. We will have 2 unbroken pairs with a total weight of 26g, which means we put them on one scale pan, and the remaining weights can be placed on the other scale and they will also be 26g.

Good luck in the development of your children.

Today we will consider one of the math problems that I had to solve with my nephew. And then we will implement it through PHP. And we will consider several options for solving this problem.

The task:

You need to quickly add all the numbers from 1 to 100 one after another and find out the sum of all the numbers.

The solution of the problem:

In fact, when we solved this problem for the first time, we did not solve it correctly! But we will not write about the wrong solution to this problem.

And the solution is so simple and trivial - you need to add 1 and 100 and multiply by 50. (Karl Gaus had such a solution when he was very young ...)

(1 + 100)*50.

How to solve this problem through php?

Calculate the sum of all numbers from 1 to 100 via PHP.

When we have already solved this problem, we decided to see what they write on the Internet on this issue! And I found some form where young talents could not solve this problem and tried to do it through a cycle.

If there is no special condition to do it through the loop, then there is no point in doing it through the loop!

And yes! Do not forget that in php you can solve the problem in many ways! one.

This code can add any sequence of numbers in general, starting from one and up to infinity.

Let's implement our solution in its simplest form:

$ end = $ _POST ["peremennaya"];

$ res = $ end / 2 * ($ i + $ end);

Result:

Calculate the sum of all numbers from any number to any number via PHP.

2.

And let's check the transmitted data for a number ...

$ two = strip_tags ($ _ POST ["peremennaya_2"]);

$ tree = strip_tags ($ _ POST ["peremennaya_3"]);

if ((is_numeric ($ two)) and (is_numeric ($ tree)))

$ res = $ tree / 2 * ($ two + $ tree);

echo " Result: ". $ Res;

echo "You don't need to put any crap in the mold ...";

The first parameter is zero ($ i = 1), the second parameter is less than or equal to this number ($ i< $end;), которое будет оправлено через форму.

Let's show the sequence, how it will increase with each new iteration of the cycle.

$ end = strip_tags ($ _ POST ["peremennaya"]);

for ($ i = 1; $ i< $end; $i++) {

$ res = $ res + $ i;

echo $ res. "
";