Problem
Übersetzung anzeigenAdd the positive divisors of n that are strictly smaller than n. If their sum equals n, the number is perfect. If the sum is larger, it is abundant; if smaller, it is deficient. The number 1 has no proper positive divisors, so its divisor sum is 0.
Implement perfect_number(n).
Input
n: The positive integer to classify.
Output
Return perfect, abundant, or deficient as lowercase text.
Einschränkungen
1 ≤ n ≤ 1,000,000. Zero and negative values are excluded.
Beispiele
Eingabe:
n = 18
Erwartete Ausgabe:
expected = "abundant"
Eingabe:
long long n = 18;
Erwartete Ausgabe:
std::string expected = "abundant";
Eingabe:
long n = 18;
Erwartete Ausgabe:
string expected = "abundant";
Erläuterung
The proper divisors are 1, 2, 3, 6, and 9. Their sum is 21, greater than 18.
Eingabe:
n = 28
Erwartete Ausgabe:
expected = "perfect"
Eingabe:
long long n = 28;
Erwartete Ausgabe:
std::string expected = "perfect";
Eingabe:
long n = 28;
Erwartete Ausgabe:
string expected = "perfect";
Erläuterung
The proper divisors sum to 1 + 2 + 4 + 7 + 14 = 28, exactly the number itself.
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.