Coding Problem|Armstrong Numbers

Input: N = 153
Output: "Yes"
Explanation: 153 is an Armstrong number
since 13 + 53 + 33 = 153.
Hence answer is "Yes".
Input: N = 370
Output: "Yes"
Explanation: 370 is an Armstrong number
since 33 + 73 + 03 = 370.
Hence answer is "Yes".

/* 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 double
void 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)

--

--

--

Student of Computer Science & Engineering at Moradabad Institute of Technology.

Love podcasts or audiobooks? Learn on the go with our new app.

Co-Cooperative Infrastructure Services: SWARM

ARTEMIS.RED - Your friendly neighborhood Validator

My Favourite VS Code Extensions.

Verilog code for Sine Cos and Arctan Xilinx CORDIC IP core

Verilog code for Sine Cos and Arctan Xilinx CORDIC IP core

Managing In-Production AWS Lambda Functions with API Gateway

UPI Payment Apps review — Google Play Store

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akash Kumar

Akash Kumar

Student of Computer Science & Engineering at Moradabad Institute of Technology.

More from Medium

Using JavaScript to Update the DOM on Dropdown Selection: One Example

Vite.js

Understanding the stack data structure in JavaScript— How does JavaScript use it?

Ditching my Array Methods Cheat Sheet