Contents | Next | Previous The Sieve of Eratosthenes The Sieve of Erathosthenes is the most effective way to find all of the small prime numbers. Your first step is to make a list of all the integers less than or equal to n (n being the largest number you want to check) and also greater than one. Next, you need to cross out all of the multiples of the prime numbers less than or equal to the square root of n. Finally, the numbers you have left are the prime numbers. For example, let�s let n be equal to 26. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Now, in our list 2 is the first prime. Therefore, cross out all the multiples of two. You are left with: 3 5 7 9 11 13 15 17 19 21 23 25 Now, the first number (3) left is our first odd prime. Therefore, cross out all the multiples of three. You are left with: 5 7 11 13 17 19 23 25 Now, the first number left (5) is the second odd prime. Therefore, cross out all the multiples of five. You are left with: 7 11 13 17 19 23 Now, the first number left (7) is the third odd prime. Therefore, cross out all the multiples of seven. You are left with: 11 13 17 19 23 Now, the first number left (11) is the fourth odd prime. Therefore, cross out all the multiples of eleven. You are left with: 13 17 19 23 Now, the first number left (13) is the fifth odd prime. Therefore, cross out all the multiples of thirteen. You are left with: 17 19 23 Now, the first number left (17) is the sixth odd prime. Therefore, cross out all the multiples of seventeen. You are left with: 19 23 Now, the first number left (19) is the seventh odd prime. Therefore, cross out all the multiples of nineteen. You are left with: 23 Finally, the first number left (23) is the eighth odd prime. Therefore, cross out all the multiples of twenty-three. You are left with: Nothing Now, we know that there are eight odd primes less than twenty-six. There is also an even prime (2) less than twenty-six. That makes a total of 9 primes less than twenty-six. Click on this link to read about Eratosthenes. Here is a pseudo-code that can be used to generate all prime numbers. Eratosthenes(n) { a[1] :=0 for i :=2 to n do a[i] :=1 p:=2 while p^2<=n do { j:=2p while (j<=n) do { a[j]:=0 j:=j+p } repeat p :=p+1 until a[p]=1 } return (a) } Contributed by Jeremy Troutman References: URL:http://www.utm.edu/research/primes/glossary/SieveOfEratosthenes.html 6-13-00 8:00 PM. Contents | Next | Previous Making Magic Squares On Changing Squares into Doughnuts Unraveling the mystery of the magic square and learning how to construct them is not very difficult. The truths follow... It is beneficial to understand what a magic square is. According to a definition by Allen Adler �A magic square is an arrangement of the numbers from 1 to n2 in an nxn matrix, with each number occurring only once, such that the sums of any row, any column, or any main diagonal is the same.� The sum will satisfy n(n2 + 1)/2. Read on to find out how to make you own... The simplest magic square is the 1x1 magic square, with the only entry being the number 1. There aren�t any 2x2 magic square because the above equation cannot be satisfied with the numbers 1 through 4. Each odd numbered magic square, 3x3, 5x5, etc., are constructed in a similar manner. When there are odd number of columns and rows, start with the number 1 in the middle column, first row. From here, continue filling the square by this method: move up one square and to the right one square. Three things could cause you to feel as though your magic went astray. There are ways to overcome the puzzles that ail you: 1. You are at the top row of your square and have no place to go. *Pretend the top edge is pasted to the bottom edge and come up through the bottom, still moving up and to the right. 2. You are at the right side of the square and, again, have no place to go. *Pretend the right edge is pasted to the left edge. Continuing to move up and to the right, the four would be in the left most column, third row. Fill in the number five as well. 3. Now, look what you have done, where will you put the 6? For this situation, when there is a number already occupying the space, you must abandon the rules, but don�t give up! Place the six directly under the five. Remember this rule for the future. Through hard work and concentration, you will eventually have worked enough magic to make a square like this one: You may have some trouble placing number 16. Follow each of the above rules and you will succeed! How is making magic squares like making doughnuts? Refer to rules 1 and 2 that were given above that helped you do your magic. Those rules will help you again. When you reached the edge of the square you were instructed to pretend to paste the top edge to the bottom edge, matching up the columns. If you were to do this, you would make a cylinder. You also pasted the left side to the right side, matching up each row to itself. If you do this after constructing the cylinder, the ends of the cylinder would be pasted together. Now say: You are truly a magician. You changed the magic square into a doughnut!! Please refer to http://mathforum.com/alejandre/magic.square/adler for more information on magic squares. Definition, Special Properties A magic square is an arrangement of the numbers from 1 to n^2 (n-squared) in an nxn matrix, with each number occurring exactly once, and such that the sum of the entries of any row, any column, or any main diagonal is the same. It is not hard to show that this sum must ben(n^2+1)/2. The simplest magic square is the 1x1 magic square whose only entry is the number 1. The next simplest is the 3x3 magic square and those derived from it by symmetries of the square. This 3x3 square is definitely magic and satisfies the definition given above. The 4x4 Dürer magic square (or, what is essentially the same, the 4x4 magic square I use) has many interesting special properties that are not shared by magic squares in general. They are so interesting that they are often pointed out when this square is presented. That is good, but can sometimes lead to misunderstandings as to which is the meat and which is the gravy. The meat is the definition I gave above. The gravy (or some of it), suggested by Jerome S. Meyer in his book, Fun with Mathematics , follows. In the case of this 4x4 magic square: in addition to having the sum 34 (= 4(4^2+1)/2) in each row, column and main diagonal, 1. The four corners add to 34. 2. The four numbers in the center add to 34. 3. The 15 and 14 in the top row and the 3 and 2 facing them in the bottom row add to 34. 4. The 12 and 8 in the first column and the 9 and 5 facing them in the last column add to 34. 5. The four squares in the corners add to 34. 6. If you go clockwise around the square and choose the first squares away from the corners (15,9,2,8), they add to 34. The same holds if you go counterclockwise. 7. If you replace each entry by its square, you get the following square: This square is not magic, but it has some noteworthy properties: 1. The first and last column have the same sum; likewise the 2nd and 3rd columns have the same sum; 2. The same holds with rows instead of columns (although the sums one gets are different from the sums for the columns); 3. From (1) and (2), it follows that the left half of the square has the same sum as the right half and that this is one-half the sum of all of the numbers in the square. The same holds for the top half and the bottom half; hence the left half equals the right half equals the top half equals the bottom half. Furthermore, this also equals the sum of the 8 numbers on the diagonals and the sum of the 8 numbers off the diagonals. 8. If instead you replace each entry by its cube, you get the following square: This square has the property that the sum of the 8 numbers on the diagonals equals the sum of the 8 numbers off the diagonals.