1 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 27 28 29 30 31 32
|
According to legend, when the creator of the game of chess showed his invention to the ruler of the country, the ruler was so pleased that he gave the inventor the right to name his prize for the invention. The man, who was very wise, asked the king this: that for the first square of the chessboard, he would receive one grain of wheat, two for the second one, four on the third one, and so forth, doubling the amount each time. The ruler, arithmetically unaware, quickly accepted the inventor's offer, even getting offended by his perceived notion that the inventor was asking for such a low price, and ordered the treasurer to count and hand over the wheat to the inventor.
How many grains of wheat would be on the chessboard at the finish?
To solve this, observe that a chessboard is an 8×8 square, containing 64 squares (shown below).
[01] [02] [03] [04] [05] [06] [07] [08]
[09] [10] [11] [12] [13] [14] [15] [16]
[17] [18] [19] [20] [21] [22] [23] [24]
[25] [26] [27] [28] [29] [30] [31] [32]
[33] [34] [35] [36] [37] [38] [39] [40]
[41] [42] [43] [44] [45] [46] [47] [48]
[49] [50] [51] [52] [53] [54] [55] [56]
[57] [58] [59] [60] [61] [62] [63] [64]
If the amount doubles on successive squares, then the sum of grains on all 64 squares is:
Image:Wheat.png
Show the number of grains of wheat on each square of the board as well as the total grains of wheat for the board. Your output should look similar to this:
Square 1: 1 grain
Square 2: 2 grains
Square 3: 4 grains
.
.
.
Square 64: ??? grains
Total Grains of Wheat = ???
Save your source code for Exercise One as wheat.cpp.
|