Coding Problem|Armstrong Numbers
Problem Statement:
For a given 3 digit number, find whether it is armstrong number or not. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. Return “Yes” if it is a armstrong number else return “No”.
NOTE: 371 is an Armstrong number since 33 + 73 + 13 = 371
Example 1:
Input: N = 153
Output: "Yes"
Explanation: 153 is an Armstrong number
since 13 + 53 + 33 = 153.
Hence answer is "Yes".
Example 2:
Input: N = 370
Output: "Yes"
Explanation: 370 is an Armstrong number
since 33 + 73 + 03 = 370.
Hence answer is "Yes".
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
100 ≤ n <1000

Code & Algorithm:
/* author : @akash *//*
problem is:-*/#include<bits/stdc++.h>
using namespace std;#define ll long long int
#define pb push_back
#define mod 1000000007
#define ld long doublevoid solve()
{
int n;
cin>>n;
int ans=0;
int N=n;
while(n)
{
int r=n%10;
ans+=r*r*r;
n=n/10;
}
if(ans==N)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
}int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
cout<<"\n";
}
return 0;
}// time complexity of this algorithm is : T(n)=O(1)