---
# System prepended metadata

title: \#507 Perfect Number
tags: [leetcode, leetcode-easy]

---

# \#507 Perfect Number
## *給定正整數num, 回傳其因數和是否等於num*
## Log
 - build 20211003 by syhuang

## 列舉法(已知解,直接判斷)
 - 無言
 - leetcode submit runtime 97%, memory 71%
```javascript=
var checkPerfectNumber = function(num) {
    return num == 6 || num == 28 || num == 496 || num == 8128 || num == 33550336;
};
```
## 初見
 - 因數組合((a,b), a*b=num)必小於等於Math.sqrt(num)
 - 從2開始跑迴圈至Math.sqrt(num)逐一檢查
 - leetcode submit runtime 90%, memory 14%
```javascript=
var checkPerfectNumber = function(num) {
    if(num==1) return false;
    let snum = Math.sqrt(num);
    let total = 1;
    for(let i=2; i<=snum; i++){
        if(num%i==0){
            total+=(i+num/i);
        }
    }
    return total==num;
};
```
## 備註
## 參考
###### tags: `leetcode`, `leetcode-easy`