友好數
Opened this issue · 0 comments
Ponchimeow commented
function pe(input) {
const n = parseInt(input);
let nSum = factor(n).reduce(function (acc, cur) {
return acc + cur
});
if (nSum === 1) return `0`;
if (nSum === n) return `=${n}`;
let mSum = factor(nSum).reduce(function (acc, cur) {
return acc + cur
});
if (mSum === n) return `${nSum}`;
return `0`;
}
function factor(num) {
let factor = [];
for (let i = 1; i < num; i += 1) {
if (num % i === 0) factor.push(i);
}
return factor;
}