這是一個難得休息的周六楞卡,怒刷一題
1390. 四因數(shù)
# @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