add: 完美数

This commit is contained in:
2020-05-22 13:30:10 +08:00
parent bf6f71f55f
commit 6a8d487f93
3 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,16 @@
const pn = (p) => { // 欧几里得-欧拉定理
return (1 << (p - 1)) * ((1 << p) - 1)
}
/**
* @param {number} num
* @return {boolean}
*/
export const checkPerfectNumber = function (num) {
const primes = [2, 3, 5, 7, 13, 17, 19, 31]
for (const prime of primes) {
if (pn(prime) === num) return true
}
return false
}