2021-06-15 00:49:18 -07:00
---
id: 594810f028c0303b75339acd
2021-08-10 22:38:37 +09:00
title: 'Classificazione dei numeri abbondanti, carenti e perfetti'
2021-06-15 00:49:18 -07:00
challengeType: 5
forumTopicId: 302221
dashedName: abundant-deficient-and-perfect-number-classifications
---
# --description--
2021-08-10 22:38:37 +09:00
Queste definiscono tre classificazioni di numeri interi positivi basate sui loro divisori.
2021-06-15 00:49:18 -07:00
2021-08-10 22:38:37 +09:00
Sia $P(n)$ la somma dei divisori di `n` dove i divisori sono tutti interi positivi `n` diversi da `n` stesso.
2021-06-15 00:49:18 -07:00
2021-08-10 22:38:37 +09:00
Se `P(n) < n` allora `n` è classificato come `deficient`
2021-06-15 00:49:18 -07:00
2021-08-10 22:38:37 +09:00
Se `P(n) === n` allora `n` è classificato come `perfect`
2021-06-15 00:49:18 -07:00
2021-08-10 22:38:37 +09:00
Se `P(n) > n` allora `n` è classificato come `abundant`
2021-06-15 00:49:18 -07:00
2021-08-10 22:38:37 +09:00
**Esempio**: `6` ha i divisori `1` , `2` e `3` . `1 + 2 + 3 = 6` , quindi `6` è classificato come numero perfetto.
2021-06-15 00:49:18 -07:00
# --instructions--
2021-08-10 22:38:37 +09:00
Implementa una funzione che calcola quanti numeri interi tra `1` e `num` (inclusi) sono in queste tre categorie. Restituisci il risultato come un array nel seguente formato `[deficient, perfect, abundant]` .
2021-06-15 00:49:18 -07:00
# --hints--
2021-08-10 22:38:37 +09:00
`getDPA` dovrebbe essere una funzione.
2021-06-15 00:49:18 -07:00
```js
assert(typeof getDPA === 'function');
```
2021-08-10 22:38:37 +09:00
`getDPA(5000)` dovrebbe restituire un array.
2021-06-15 00:49:18 -07:00
```js
assert(Array.isArray(getDPA(5000)));
```
2021-08-10 22:38:37 +09:00
`getDPA(5000)` dovrebbe restituire un array di lunghezza `3` .
2021-06-15 00:49:18 -07:00
```js
assert(getDPA(5000).length === 3);
```
2021-08-10 22:38:37 +09:00
`getDPA(5000)` dovrebbe restituire `[3758, 3, 1239]` .
2021-06-15 00:49:18 -07:00
```js
assert.deepEqual(getDPA(5000), [3758, 3, 1239]);
```
2021-08-10 22:38:37 +09:00
`getDPA(10000)` dovrebbe restituire `[7508, 4, 2488]` .
2021-06-15 00:49:18 -07:00
```js
assert.deepEqual(getDPA(10000), [7508, 4, 2488]);
```
2021-08-10 22:38:37 +09:00
`getDPA(20000)` dovrebbe restituire `[15043, 4, 4953]` .
2021-06-15 00:49:18 -07:00
```js
assert.deepEqual(getDPA(20000), [15043, 4, 4953]);
```
# --seed--
## --seed-contents--
```js
function getDPA(num) {
}
```
# --solutions--
```js
function getDPA(num) {
const dpa = [1, 0, 0];
for (let n = 2; n < = num; n += 1) {
let ds = 1;
const e = Math.sqrt(n);
for (let d = 2; d < e ; d + = 1 ) {
if (n % d === 0) {
ds += d + (n / d);
}
}
if (n % e === 0) {
ds += e;
}
dpa[ds < n ? 0 : ds = == n ? 1 : 2 ] + = 1 ;
}
return dpa;
}
```