数学のブログ

“離散的”な世界 等差数列の和 自然数の表、行と列

新装版 数学読本3 (松坂 和夫(著)、岩波書店)の第13章(“離散的”な世界 - 数列)、13.1(数列とその和)、等差数列の和の問11の解答を求めてみる。

1

m ( 1 + m ) 2

2

1 + n ( 0 + ( n - 1 ) ) 2 = 1 + n ( n - 1 ) 2

3

( m + n - 2 ) ( m + n - 1 ) 2 + m

4

( m + n - 2 ) ( m + n - 1 ) 2 + m = 100
( m + n - 2 ) ( m + n - 1 ) 2 = 100 - m
( m + n - 2 ) ( m + n - 1 ) 2 < 100
( m + n - 2 ) ( m + n - 1 ) < 200
m + n < 16
m + n = 15
13 · 14 2 + m = 100
m = 100 - 91 = 9 n = 6

コード

#!/usr/bin/env python3
from unittest import TestCase, main
import pprint

print('11.')

table = [[(m + n - 2) * (m + n - 1) / 2 + m for n in range(1, 11)]
         for m in range(1, 11)]

pprint.pprint(table)


class Test(TestCase):
    def test1(self):
        for m in range(1, 11):
            self.assertEqual(table[m - 1][0], m * (1 + m) / 2)

    def test2(self):
        for n in range(1, 11):
            self.assertEqual(table[0][n - 1], 1 + n * (n - 1) / 2)

    def test4(self):
        self.assertEqual(table[9 - 1][6 - 1], 100)


if __name__ == "__main__":
    main()

入出力結果

% ./sample11.py -v
11.
[[1.0, 2.0, 4.0, 7.0, 11.0, 16.0, 22.0, 29.0, 37.0, 46.0],
 [3.0, 5.0, 8.0, 12.0, 17.0, 23.0, 30.0, 38.0, 47.0, 57.0],
 [6.0, 9.0, 13.0, 18.0, 24.0, 31.0, 39.0, 48.0, 58.0, 69.0],
 [10.0, 14.0, 19.0, 25.0, 32.0, 40.0, 49.0, 59.0, 70.0, 82.0],
 [15.0, 20.0, 26.0, 33.0, 41.0, 50.0, 60.0, 71.0, 83.0, 96.0],
 [21.0, 27.0, 34.0, 42.0, 51.0, 61.0, 72.0, 84.0, 97.0, 111.0],
 [28.0, 35.0, 43.0, 52.0, 62.0, 73.0, 85.0, 98.0, 112.0, 127.0],
 [36.0, 44.0, 53.0, 63.0, 74.0, 86.0, 99.0, 113.0, 128.0, 144.0],
 [45.0, 54.0, 64.0, 75.0, 87.0, 100.0, 114.0, 129.0, 145.0, 162.0],
 [55.0, 65.0, 76.0, 88.0, 101.0, 115.0, 130.0, 146.0, 163.0, 181.0]]
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok
test4 (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.000s

OK
%