Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int n, m;
- void input() {
- cin >> n >> m;
- }
- int socs(int x) {
- int dem = 0;
- while(x > 0) {
- x = x/10;
- dem++;
- }
- return dem;
- }
- bool isAmstrong(int x) {
- int tmp = x;
- int soMu = socs(x);
- int tong = 0;
- while(x > 0) {
- int t = x %10;
- int mut =pow(t, soMu);
- tong += mut;
- x/=10;
- }
- if(tong == tmp) return true;
- return false;
- }
- void findAmstrong() {
- int dem = 0;
- if(n < m) {
- for(int i = n; i<=m; i++) {
- if(isAmstrong(i)) {
- dem++;
- cout << i << " ";
- }
- }
- } else {
- for(int i = m; i <= n; i++) {
- if(isAmstrong(i)) {
- dem++;
- cout << i << " ";
- }
- }
- }
- if(dem == 0)
- cout << "0";
- }
- int main() {
- input();
- findAmstrong();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement