2018年11月4日日曜日

181104

Ruby


A129373

A(x) = (1+x) * A(x^2) * A(x^3) * A(x^4) * ... * A(x^n) * ...
を満たすA(x) について考える。
(1+x) * A(x^2),
(1+x) * A(x^2) * A(x^3),
(1+x) * A(x^2) * A(x^3) * A(x^4),
...
がA(x) に近づくさまを出力してみた。

# m次以下を取り出す
def mul(f_ary, b_ary, m)
  s1, s2 = f_ary.size, b_ary.size
  ary = Array.new(s1 + s2 - 1, 0)
  (0..s1 - 1).each{|i|
    (0..s2 - 1).each{|j|
      ary[i + j] += f_ary[i] * b_ary[j]
    }
  }
  ary[0..m]
end

def s(f_ary, g_ary, n)
  s = 0
  (1..n).each{|i| s += i * f_ary[i] * g_ary[i] ** (n / i) if n % i == 0}
  s
end

def A(f_ary, g_ary, n)
  ary = [1]
  a = [0] + (1..n).map{|i| s(f_ary, g_ary, i)}
  (1..n).each{|i| ary << (1..i).inject(0){|s, j| s + a[j] * ary[-j]} / i}
  ary
end

def S(n)
  a = [0, 1]
  (2..n).each{|i|
    s = 0
    (1..i - 1).each{|j|
      s += a[j] if i % j == 0
    }
    a << s
  }
  a
end

def B(n)
  ary1 = S(n).map{|i| -i}
  ary2 = Array.new(n + 1, -1)
  A(ary1, ary2, n)
end

n = 20
ary = B(n)
a = Array.new(n + 1, 0)
a[0] = 1
a[1] = 1
p [1, a]
(2..n).each{|i|
  b = Array.new(n + 1, 0)
  (0..n / i).each{|j| b[i * j] = ary[j]}
  a = mul(a, b, n)
  p [i, a]
}

出力結果
[1, [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
[2, [1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 7, 7, 9, 9, 13, 13, 19, 19, 26]]
[3, [1, 1, 1, 2, 2, 2, 4, 4, 5, 8, 9, 10, 17, 18, 21, 30, 35, 39, 58, 64, 76]]
[4, [1, 1, 1, 2, 3, 3, 5, 6, 8, 11, 14, 16, 26, 30, 36, 48, 64, 72, 99, 118, 148]]
[5, [1, 1, 1, 2, 3, 4, 6, 7, 10, 14, 18, 22, 33, 40, 50, 67, 87, 106, 141, 171, 219]]
[6, [1, 1, 1, 2, 3, 4, 7, 8, 11, 16, 21, 26, 40, 48, 61, 83, 108, 132, 182, 220, 281]]
[7, [1, 1, 1, 2, 3, 4, 7, 9, 12, 17, 23, 29, 44, 55, 70, 95, 125, 155, 211, 264, 336]]
[8, [1, 1, 1, 2, 3, 4, 7, 9, 13, 18, 24, 31, 47, 59, 77, 104, 138, 173, 235, 295, 383]]
[9, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 25, 32, 49, 62, 81, 111, 147, 186, 254, 320, 415]]
[10, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 26, 33, 50, 64, 84, 115, 154, 195, 267, 339, 441]]
[11, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 26, 34, 51, 65, 86, 118, 158, 202, 276, 352, 460]]
[12, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 26, 34, 52, 66, 87, 120, 161, 206, 283, 361, 473]]
[13, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 26, 34, 52, 67, 88, 121, 163, 209, 287, 368, 482]]
[14, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 26, 34, 52, 67, 89, 122, 164, 211, 290, 372, 489]]
[15, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 26, 34, 52, 67, 89, 123, 165, 212, 292, 375, 493]]
[16, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 26, 34, 52, 67, 89, 123, 166, 213, 293, 377, 496]]
[17, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 26, 34, 52, 67, 89, 123, 166, 214, 294, 378, 498]]
[18, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 26, 34, 52, 67, 89, 123, 166, 214, 295, 379, 499]]
[19, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 26, 34, 52, 67, 89, 123, 166, 214, 295, 380, 500]]
[20, [1, 1, 1, 2, 3, 4, 7, 9, 13, 19, 26, 34, 52, 67, 89, 123, 166, 214, 295, 380, 501]]

0 件のコメント:

コメントを投稿

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