Ruby
A292105
A292105
正n 角形において、ちょうどk 本の対角線が交わる点の数を出力してみた。
def d(n, k)
n % k == 0 ? 1 : 0
end
def a2(n)
s = (n ** 3 - 6 * n * n + 11 * n - 6) / 24r
s += (- 5 * n * n + 46 * n - 72) / 16r * d(n, 2)
s -= 9 / 4r * d(n, 4)
s += (-19 * n + 110) / 2r * d(n, 6)
s += 54 * d(n, 12)
s += 84 * d(n, 18)
s += 50 * d(n, 24)
s -= 24 * d(n, 30)
s -= 100 * d(n, 42)
s -= 432 * d(n, 60)
s -= 204 * d(n, 84)
s -= 144 * d(n, 90)
s -= 204 * d(n, 120)
s -= 144 * d(n, 210)
(n * s).to_i
end
def a3(n)
s = (5 * n * n - 48 * n + 76) / 48r * d(n, 2)
s += 3 / 4r * d(n, 4)
s += (7 * n - 38) / 6r * d(n, 6)
s -= 8 * d(n, 12)
s -= 20 * d(n, 18)
s -= 16 * d(n, 24)
s -= 19 * d(n, 30)
s += 8 * d(n, 42)
s += 68 * d(n, 60)
s += 60 * d(n, 84)
s += 48 * d(n, 90)
s += 60 * d(n, 120)
s += 48 * d(n, 210)
(n * s).to_i
end
def a4(n)
s = (7 * n - 42) / 12r * d(n, 6)
s -= 5 / 2r * d(n, 12)
s -= 4 * d(n, 18)
s += 3 * d(n, 24)
s += 6 * d(n, 42)
s += 34 * d(n, 60)
s -= 6 * d(n, 84)
s -= 6 * d(n, 120)
(n * s).to_i
end
def a5(n)
s = (n - 6) / 4r * d(n, 6)
s -= 3 / 2r * d(n, 12)
s -= 2 * d(n, 24)
s += 4 * d(n, 42)
s += 6 * d(n, 84)
s += 6 * d(n, 120)
(n * s).to_i
end
def a6(n)
n * (4 * d(n, 30) - 4 * d(n, 60))
end
def a7(n)
n * (d(n, 30) + 4 * d(n, 60))
end
def a(n, k)
return a2(n) if k == 2
return a3(n) if k == 3
return a4(n) if k == 4
return a5(n) if k == 5
return a6(n) if k == 6
return a7(n) if k == 7
end
def A(n)
return [0] if n < 4
return [0, a(n, 2)] if n % 2 == 1
return [0] + (2..n / 2 - 1).map{|i| a(n, i)} + [1] if n / 2 < 9
[0] + (2..7).map{|i| a(n, i)} + [0] * (n / 2 - 8) + [1]
end
n = 100
(1..n).each{|i|
print i
print ':'
p A(i)
}
出力結果
1:[0]
2:[0]
3:[0]
4:[0, 1]
5:[0, 5]
6:[0, 12, 1]
7:[0, 35]
8:[0, 40, 8, 1]
9:[0, 126]
10:[0, 140, 20, 0, 1]
11:[0, 330]
12:[0, 228, 60, 12, 0, 1]
13:[0, 715]
14:[0, 644, 112, 0, 0, 0, 1]
15:[0, 1365]
16:[0, 1168, 208, 0, 0, 0, 0, 1]
17:[0, 2380]
18:[0, 1512, 216, 54, 54, 0, 0, 0, 1]
19:[0, 3876]
20:[0, 3360, 480, 0, 0, 0, 0, 0, 0, 1]
21:[0, 5985]
22:[0, 5280, 660, 0, 0, 0, 0, 0, 0, 0, 1]
23:[0, 8855]
24:[0, 6144, 864, 264, 24, 0, 0, 0, 0, 0, 0, 1]
25:[0, 12650]
26:[0, 11284, 1196, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
27:[0, 17550]
28:[0, 15680, 1568, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
29:[0, 23751]
30:[0, 13800, 2250, 420, 180, 120, 30, 0, 0, 0, 0, 0, 0, 0, 1]
31:[0, 31465]
32:[0, 28448, 2464, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
33:[0, 40920]
34:[0, 37264, 2992, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
35:[0, 52360]
36:[0, 42444, 3924, 396, 216, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
37:[0, 66045]
38:[0, 60648, 4332, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
39:[0, 82251]
40:[0, 75720, 5160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
41:[0, 101270]
42:[0, 75012, 8148, 1134, 546, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
43:[0, 123410]
44:[0, 114400, 7040, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
45:[0, 148995]
46:[0, 138644, 8096, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
47:[0, 178365]
48:[0, 152064, 10560, 1200, 336, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
49:[0, 211876]
50:[0, 198200, 10600, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
51:[0, 249900]
52:[0, 234208, 12064, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
53:[0, 292825]
54:[0, 254988, 15552, 1296, 648, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
55:[0, 341055]
56:[0, 321048, 15288, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
57:[0, 395010]
58:[0, 372708, 17052, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
59:[0, 455126]
60:[0, 375060, 25320, 3780, 720, 0, 300, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
61:[0, 521855]
62:[0, 494140, 21080, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
63:[0, 595665]
64:[0, 564800, 23360, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
65:[0, 677040]
66:[0, 605352, 30360, 2310, 990, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
67:[0, 766480]
68:[0, 728960, 28288, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
69:[0, 864501]
70:[0, 823480, 30940, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
71:[0, 971635]
72:[0, 894816, 36288, 2520, 936, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
73:[0, 1088430]
74:[0, 1039404, 36852, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
75:[0, 1215450]
76:[0, 1161888, 40128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
77:[0, 1353275]
78:[0, 1241760, 50076, 3276, 1404, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
79:[0, 1502501]
80:[0, 1439440, 47120, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
95:[0, 3183545]
96:[0, 2999040, 91008, 5088, 1824, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
97:[0, 3464840]
98:[0, 3345328, 88592, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
99:[0, 3764376]
100:[0, 3636800, 94400, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。