Magic Square problem:
-
Some perfect squares have unique mathematical properties. For example, 36 is:
- a perfect square, 62
- the sum of the integers 1 to 8 (1+2+3+4+5+6+7+8 = 36)
- a “magic square” (any number that is both a perfect square AND equal to the sum of consecutive integers beginning with 1)
The next magic square is 1225:
- 352 = 1225
- 1225 = sum of 1 to 49
Write a method that prints the first n magic squares.
-
Least Common Multiple (LCM) problem:
- Write a method that determines the Least Common Multiple of two integers. For example, the LCM of the following pairs:
2, 3 |
LCM = 6 |
4, 10 |
LCM = 20 |
12, 15 |
LCM = 60 |
7, 70 |
LCM = 70 |
Find the first four magic squares. The first one is the integer 1.
- Find the LCM of the following pairs of values:
15, 18
40, 12
2, 7
100, 5
- Try finding the first 10 magic squares. This program will take so long that you can accurately time it. Experiment with this program by running it on computers with different clock speeds (number of megahertz).