आसान 0 हल किए गए 0% स्वीकृति

Classify a Number by Its Divisors

Classify a positive integer as perfect, abundant, or deficient.

आप क्या सीखेंगे

  • Find all proper divisors of a number
  • Speed up divisor search with the square root
  • Classify results with conditions

समस्या

अनुवाद दिखाएँ

Add 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.

सीमाएँ

1 ≤ n ≤ 1,000,000. Zero and negative values are excluded.

उदाहरण

उदाहरण 1
इनपुट:
n = 18

अपेक्षित आउटपुट:
expected = "abundant"
इनपुट:
long long n = 18;

अपेक्षित आउटपुट:
std::string expected = "abundant";
इनपुट:
long n = 18;

अपेक्षित आउटपुट:
string expected = "abundant";

व्याख्या

The proper divisors are 1, 2, 3, 6, and 9. Their sum is 21, greater than 18.

उदाहरण 2
इनपुट:
n = 28

अपेक्षित आउटपुट:
expected = "perfect"
इनपुट:
long long n = 28;

अपेक्षित आउटपुट:
std::string expected = "perfect";
इनपुट:
long n = 28;

अपेक्षित आउटपुट:
string expected = "perfect";

व्याख्या

The proper divisors sum to 1 + 2 + 4 + 7 + 14 = 28, exactly the number itself.

कैसे हल करें

पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।

संकेत 1

Find the proper divisors of n and compare their sum with n to decide the class.

संकेत 2

You only need to search divisors up to the square root, pairing each divisor with its companion.

संकेत 3

Treat 1 carefully, since it has no proper positive divisors and its divisor sum is zero.

अपेक्षित जटिलता

O(√n) time, O(1) extra space

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।