If you look at the loop results carefully, you will discover that the number of grains on each square 1 to 64 is equal to 2**(square-1) and the number of total accumulated grains at this point is (2**square) – 1
这是一些代码…
”’ chessboard_grains2.py
putting one grain of rice on the first square of a chessboard
two grains of rice on the second square
and doubling it every remaining square
tested with Python34 by vegaseat 13may2015
”’
for square in range(1, 64+1):
grains = 2**(square-1)
grains_sum = (2**square) – 1
print(“square {} grains = {} total= {}”.format(square, grains, grains_sum))
”’ result …
square 1 grains = 1 total= 1
square 2 grains = 2 total= 3
square 3 grains = 4 total= 7
square 4 grains = 8 total= 15
square 5 grains = 16 total= 31
square 6 grains = 32 total= 63
square 7 grains = 64 total= 127
square 8 grains = 128 total= 255
square 9 grains = 256 total= 511
square 10 grains = 512 total= 1023
square 11 grains = 1024 total= 2047
square 12 grains = 2048 total= 4095
square 13 grains = 4096 total= 8191
square 14 grains = 8192 total= 16383
square 15 grains = 16384 total= 32767
square 16 grains = 32768 total= 65535
square 17 grains = 65536 total= 131071
square 18 grains = 131072 total= 262143
square 19 grains = 262144 total= 524287
square 20 grains = 524288 total= 1048575
square 21 grains = 1048576 total= 2097151
square 22 grains = 2097152 total= 4194303
square 23 grains = 4194304 total= 8388607
square 24 grains = 8388608 total= 16777215
square 25 grains = 16777216 total= 33554431
square 26 grains = 33554432 total= 67108863
square 27 grains = 67108864 total= 134217727
square 28 grains = 134217728 total= 268435455
square 29 grains = 268435456 total= 536870911
square 30 grains = 536870912 total= 1073741823
square 31 grains = 1073741824 total= 2147483647
square 32 grains = 2147483648 total= 4294967295
square 33 grains = 4294967296 total= 8589934591
square 34 grains = 8589934592 total= 17179869183
square 35 grains = 17179869184 total= 34359738367
square 36 grains = 34359738368 total= 68719476735
square 37 grains = 68719476736 total= 137438953471
square 38 grains = 137438953472 total= 274877906943
square 39 grains = 274877906944 total= 549755813887
square 40 grains = 549755813888 total= 1099511627775
square 41 grains = 1099511627776 total= 2199023255551
square 42 grains = 2199023255552 total= 4398046511103
square 43 grains = 4398046511104 total= 8796093022207
square 44 grains = 8796093022208 total= 17592186044415
square 45 grains = 17592186044416 total= 35184372088831
square 46 grains = 35184372088832 total= 70368744177663
square 47 grains = 70368744177664 total= 140737488355327
square 48 grains = 140737488355328 total= 281474976710655
square 49 grains = 281474976710656 total= 562949953421311
square 50 grains = 562949953421312 total= 1125899906842623
square 51 grains = 1125899906842624 total= 2251799813685247
square 52 grains = 2251799813685248 total= 4503599627370495
square 53 grains = 4503599627370496 total= 9007199254740991
square 54 grains = 9007199254740992 total= 18014398509481983
square 55 grains = 18014398509481984 total= 36028797018963967
square 56 grains = 36028797018963968 total= 72057594037927935
square 57 grains = 72057594037927936 total= 144115188075855871
square 58 grains = 144115188075855872 total= 288230376151711743
square 59 grains = 288230376151711744 total= 576460752303423487
square 60 grains = 576460752303423488 total= 1152921504606846975
square 61 grains = 1152921504606846976 total= 2305843009213693951
square 62 grains = 2305843009213693952 total= 4611686018427387903
square 63 grains = 4611686018427387904 total= 9223372036854775807
square 64 grains = 9223372036854775808 total= 18446744073709551615
”’