Polite number(4)
require 'prime'
def power(a, n)
return 1 if n == 0
k = power(a, n >> 1)
k *= k
return k if n & 1 == 0
return k * a
end
def f(n)
return 0 if n == 1
factor = Prime.prime_division(n)
o_factor = factor.clone
n1 = 1
if o_factor[0][0] == 2
n1 = power(2, o_factor[0][1])
o_factor.shift
end
a0, a1 = 1, 1
o_factor.each{|i|
p, q = i[0], i[1]
a0 *= q + 1
a1 *= power(p, q + 1) / (p - 1)
}
((2 * n1 + 1) * a1 - a0) / 2 - n
end
def A(n)
(1..n).map{|i| f(i)}
end
p A(100)
[0, 0, 2, 0, 3, 3, 4, 0, 9, 4, 6, 5, 7, 5, 19, 0, 9, 13, 10, 6, 25, 7, 12, 9, 20, 8, 31, 7, 15, 28, 16, 0, 37, 10, 35, 21, 19, 11, 43, 10, 21, 36, 22, 9, 69, 13, 24, 17, 35, 26, 55, 10, 27, 44, 51, 11, 61, 16, 30, 46, 31, 17, 90, 0, 59, 52, 34, 12, 73, 48, 36, 37, 37, 20, 108, 13, 65, 60, 40, 18, 98, 22, 42, 58, 75, 23, 91, 13, 45, 102, 75, 15, 97, 25, 83, 33, 49, 43, 132, 38]
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。