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).
Append your output to the end of your source file as a comment and submit the file. Your output should look like the following:
Magic Squares
1: 1
2: 36
3: 1225
4: 41616
LCM (15, 18) = 90
LCM (40, 12) = 120
LCM (2, 7) = 14
LCM (100, 5) = 100
Magic Squares
1: 1
2: 36
3: 1225
4: 41616
5: 1413721
6: 48024900
7: 1631432881
8: 55420693056
9: 1882672131025
10: 63955431761796
11: 2172602007770041
12: 73804512832419600
13: 2507180834294496361