这是一个难得休息的周六,怒刷一题
1390. 四因数
# @param {Integer[]} nums
# @return {Integer}
def sum_four_divisors(nums)
ans = 0
a = nums.map {|it| it.pow(0.5).ceil}
nums.each_with_index do |num,i|
c = { 1 => 1, num => 1}
(2..a[i]).to_a.each do |b|
if num%b == 0 && (b != num)
c[b] = 1
c[num/b] = 1
if c.length%2 == 1 || c.length > 4
break
end
end
end
if c.length == 4
ans += c.keys.sum
end
end
ans
end