2019年4月20日土曜日

190420

Ruby


Expansion of g.f. 1/((1-x)^k-x^k)

A306915 に書いたとおり第n 項は
Sum_{j=0..floor(n/k)} binomial(n+k-1,k*j+k-1)
で表される。

def ncr(n, r)
  return 1 if r == 0
  (n - r + 1..n).inject(:*) / (1..r).inject(:*)
end

def A(k, n)
  (0..n / k).inject(0){|s, i| s + ncr(n + k - 1, k * i + k - 1)}
end

n = 50
(1..n).each{|i| p [i, (0..10).map{|j| A(i, j)}]}

出力結果
[1, [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]]
[2, [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]]
[3, [1, 3, 6, 11, 21, 42, 85, 171, 342, 683, 1365]]
[4, [1, 4, 10, 20, 36, 64, 120, 240, 496, 1024, 2080]]
[5, [1, 5, 15, 35, 70, 127, 220, 385, 715, 1430, 3004]]
[6, [1, 6, 21, 56, 126, 252, 463, 804, 1365, 2366, 4368]]
[7, [1, 7, 28, 84, 210, 462, 924, 1717, 3017, 5110, 8568]]
[8, [1, 8, 36, 120, 330, 792, 1716, 3432, 6436, 11456, 19584]]
[9, [1, 9, 45, 165, 495, 1287, 3003, 6435, 12870, 24311, 43776]]
[10, [1, 10, 55, 220, 715, 2002, 5005, 11440, 24310, 48620, 92379]]
[11, [1, 11, 66, 286, 1001, 3003, 8008, 19448, 43758, 92378, 184756]]
[12, [1, 12, 78, 364, 1365, 4368, 12376, 31824, 75582, 167960, 352716]]
[13, [1, 13, 91, 455, 1820, 6188, 18564, 50388, 125970, 293930, 646646]]
[14, [1, 14, 105, 560, 2380, 8568, 27132, 77520, 203490, 497420, 1144066]]
[15, [1, 15, 120, 680, 3060, 11628, 38760, 116280, 319770, 817190, 1961256]]
[16, [1, 16, 136, 816, 3876, 15504, 54264, 170544, 490314, 1307504, 3268760]]
[17, [1, 17, 153, 969, 4845, 20349, 74613, 245157, 735471, 2042975, 5311735]]
[18, [1, 18, 171, 1140, 5985, 26334, 100947, 346104, 1081575, 3124550, 8436285]]
[19, [1, 19, 190, 1330, 7315, 33649, 134596, 480700, 1562275, 4686825, 13123110]]
[20, [1, 20, 210, 1540, 8855, 42504, 177100, 657800, 2220075, 6906900, 20030010]]
[21, [1, 21, 231, 1771, 10626, 53130, 230230, 888030, 3108105, 10015005, 30045015]]
[22, [1, 22, 253, 2024, 12650, 65780, 296010, 1184040, 4292145, 14307150, 44352165]]
[23, [1, 23, 276, 2300, 14950, 80730, 376740, 1560780, 5852925, 20160075, 64512240]]
[24, [1, 24, 300, 2600, 17550, 98280, 475020, 2035800, 7888725, 28048800, 92561040]]
[25, [1, 25, 325, 2925, 20475, 118755, 593775, 2629575, 10518300, 38567100, 131128140]]
[26, [1, 26, 351, 3276, 23751, 142506, 736281, 3365856, 13884156, 52451256, 183579396]]
[27, [1, 27, 378, 3654, 27405, 169911, 906192, 4272048, 18156204, 70607460, 254186856]]
[28, [1, 28, 406, 4060, 31465, 201376, 1107568, 5379616, 23535820, 94143280, 348330136]]
[29, [1, 29, 435, 4495, 35960, 237336, 1344904, 6724520, 30260340, 124403620, 472733756]]
[30, [1, 30, 465, 4960, 40920, 278256, 1623160, 8347680, 38608020, 163011640, 635745396]]
[31, [1, 31, 496, 5456, 46376, 324632, 1947792, 10295472, 48903492, 211915132, 847660528]]
[32, [1, 32, 528, 5984, 52360, 376992, 2324784, 12620256, 61523748, 273438880, 1121099408]]
[33, [1, 33, 561, 6545, 58905, 435897, 2760681, 15380937, 76904685, 350343565, 1471442973]]
[34, [1, 34, 595, 7140, 66045, 501942, 3262623, 18643560, 95548245, 445891810, 1917334783]]
[35, [1, 35, 630, 7770, 73815, 575757, 3838380, 22481940, 118030185, 563921995, 2481256778]]
[36, [1, 36, 666, 8436, 82251, 658008, 4496388, 26978328, 145008513, 708930508, 3190187286]]
[37, [1, 37, 703, 9139, 91390, 749398, 5245786, 32224114, 177232627, 886163135, 4076350421]]
[38, [1, 38, 741, 9880, 101270, 850668, 6096454, 38320568, 215553195, 1101716330, 5178066751]]
[39, [1, 39, 780, 10660, 111930, 962598, 7059052, 45379620, 260932815, 1362649145, 6540715896]]
[40, [1, 40, 820, 11480, 123410, 1086008, 8145060, 53524680, 314457495, 1677106640, 8217822536]]
[41, [1, 41, 861, 12341, 135751, 1221759, 9366819, 62891499, 377348994, 2054455634, 10272278170]]
[42, [1, 42, 903, 13244, 148995, 1370754, 10737573, 73629072, 450978066, 2505433700, 12777711870]]
[43, [1, 43, 946, 14190, 163185, 1533939, 12271512, 85900584, 536878650, 3042312350, 15820024220]]
[44, [1, 44, 990, 15180, 178365, 1712304, 13983816, 99884400, 636763050, 3679075400, 19499099620]]
[45, [1, 45, 1035, 16215, 194580, 1906884, 15890700, 115775100, 752538150, 4431613550, 23930713170]]
[46, [1, 46, 1081, 17296, 211876, 2118760, 18009460, 133784560, 886322710, 5317936260, 29248649430]]
[47, [1, 47, 1128, 18424, 230300, 2349060, 20358520, 154143080, 1040465790, 6358402050, 35607051480]]
[48, [1, 48, 1176, 19600, 249900, 2598960, 22957480, 177100560, 1217566350, 7575968400, 43183019880]]
[49, [1, 49, 1225, 20825, 270725, 2869685, 25827165, 202927725, 1420494075, 8996462475, 52179482355]]
[50, [1, 50, 1275, 22100, 292825, 3162510, 28989675, 231917400, 1652411475, 10648873950, 62828356305]]

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。