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

Armstrong Number

Check whether a number equals the sum of its digits raised to the digit count.

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

  • Count the digits of a number
  • Raise each digit to the digit count and add them up
  • Compare the result with the original number

समस्या

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

A number with k digits is an Armstrong number if the sum of each digit raised to the power k equals the number. For example 153 = 1³ + 5³ + 3³.

Implement is_armstrong(n).

Input

n: A non-negative integer.

Output

Return true if n is an Armstrong number.

सीमाएँ

0 ≤ n ≤ 10¹⁸

उदाहरण

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

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

अपेक्षित आउटपुट:
bool expected = true;
इनपुट:
long n = 153;

अपेक्षित आउटपुट:
bool expected = true;

व्याख्या

1³ + 5³ + 3³ = 1 + 125 + 27 = 153.

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

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

अपेक्षित आउटपुट:
bool expected = false;
इनपुट:
long n = 10;

अपेक्षित आउटपुट:
bool expected = false;

व्याख्या

1² + 0² = 1, which is not 10.

कैसे हल करें

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

संकेत 1

Count how many digits the number has before summing powers.

संकेत 2

Compare the original number with the sum of each digit raised to that digit count.

संकेत 3

Remember that 0 is a special one-digit case.

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

O(k) time, O(1) extra space

संदर्भ

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

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

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

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