#include<iostream>
#include<cmath>
using namespace std;
int pow10(int num) {
int pow=0;
while (num >= 10)
{
num /= 10;
pow++;
}
return pow;
}
int main() {
int m, n, a = 0, b[7] = { 0 },am=0;
bool is=0;
while (cin >> n >> m)
{
is=0;
for (int i = n; i < m; i++)
{
am = 0;
int num = i;
a = pow10(i);
for (int j = 0; j <= a; j++)
{
b[j] = num % 10;
num /= 10;
}
for (int k = 0; k < 7; k++)
{
am += pow(b[k], a+1);
}
if (i == am)
{
is = 1;
cout << i << " ";
}
}
if (is == 0)
cout << "none";
cout << endl;
}
}
輸入包含兩個數字n, m(n<m, n>0, m<=1000000),代表所有尋找 armstrong number 的範圍
注意題目給的輸入說明
1. n<m
2. n>0
3. m<=1000000