Created
January 29, 2017 21:00
-
-
Save devteampentagon/4beb77db133e9d5178413cf0c4b95b7d to your computer and use it in GitHub Desktop.
Armstrong Number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define MEM(a,b) memset((a),(b),sizeof(a)) | |
#define MAX(a,b) ((a)>(b)?(a):(b)) | |
#define MIN(a,b) ((a)<(b)?(a):(b)) | |
#define MIN3(a,b,c) MIN(MIN(a,b),c) | |
#define MIN4(a,b,c,d) MIN(MIN(MIN(a,b),c),d) | |
#define In freopen("In.txt", "r", stdin); | |
#define Out freopen("out.txt", "w", stdout); | |
#define i64 long long | |
#define u64 long long unsigned | |
#define INF (1<<28) | |
using namespace std; | |
int cube(int n) | |
{ | |
return n * n * n; | |
} | |
bool isArmstrongNumber(int n) | |
{ | |
int sum = 0; | |
int n_BAK = n; | |
while(n!=0) | |
{ | |
int tmp = n%10; | |
sum += cube(tmp); | |
n /= 10; | |
} | |
if(n_BAK == sum) | |
return true; | |
return false; | |
} | |
int main() | |
{ | |
int n; | |
while(cin >> n) | |
{ | |
cout << (isArmstrongNumber(n) ? "YES" : "NO" )<< endl; | |
} | |
return 0; | |
} | |
/* | |
Sample Input and Output: | |
371 | |
YES | |
0 | |
YES | |
5 | |
NO | |
6 | |
NO | |
7 | |
NO | |
9 | |
NO | |
10 | |
NO | |
12 | |
NO | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment