#include <iostream>
#include <conio.h>
using namespace std;
int NumberToPower(int number, int power);
int Power(int in_number);
int Armstrong(int number);
int BruteForce(int number);
int main()
{
cout<<"vvedite chislo: ";
//system("cls");
int in_number=0;
cin>>in_number;
cout<<"Posledovatelnost chisel Armstronga::"<< endl<< endl;
Armstrong(in_number);
getch();
return 0;
}
int NumberToPower(int number, int power)
{
int tmp=1;
while (power)
{
if (power & 1)
tmp*=number;
number*=number;
power>>=1;
}
return tmp;
}
int Power(int in_number)
{
if (in_number<10)
return 1;
if ((in_number>9) and (in_number<100))
return 2;
if ((in_number>99) and (in_number<1000))
return 3;
if ((in_number>999) and (in_number<10000))
return 4;
if ((in_number>9999) and (in_number<100000))
return 5;
if ((in_number>99999) and (in_number<1000000))
return 6;
if ((in_number>999999) and (in_number<10000000))
return 7;
if ((in_number>9999999) and (in_number<100000000))
return 8;
if ((in_number>99999999) and (in_number<1000000000))
return 9;
if ((in_number>999999999) and (in_number<=(sizeof(unsigned int))))
return 10;
}
int Armstrong(int in_number)
{
const int size_row=10;
const int size_col=10;
int MPower[size_row][size_col]= { {0,1,2,3,4,5,6,7,8,9},
{1,0,0,0,0,0,0,0,0,0},
{2,0,0,0,0,0,0,0,0,0},
{3,0,0,0,0,0,0,0,0,0},
{4,0,0,0,0,0,0,0,0,0},
{5,0,0,0,0,0,0,0,0,0},
{6,0,0,0,0,0,0,0,0,0},
{7,0,0,0,0,0,0,0,0,0},
{8,0,0,0,0,0,0,0,0,0},
{9,0,0,0,0,0,0,0,0,0} };
int out_number=0;
int next_symb=0;
int sum=0;
unsigned short i=1;
unsigned short j=0;
while (i<=size_col-1)
{
j=1;
while (j<=size_row-1)
{
MPower[i][j]=NumberToPower(i,j);
j++;
}
i++;
}
/*************************************
* for (i=0; i<size_col; i++) *
* { *
* for (j=0; j<size_row; j++) * вывод таблицы степеней
* cout<<MPower[i][j]<<"/t"; *
* } *
**************************************/
out_number=in_number;
while (in_number>=0)
{
while (out_number)
{
if (!(out_number%10))
{
next_symb=(out_number%100)/10;
out_number/=100;
}
else
{
next_symb=out_number%10;
out_number/=10;
}
sum+=MPower[next_symb][Power(in_number)];
}
if (sum == in_number )
cout<< in_number<< " "<< endl;
in_number--;
out_number=in_number;
sum=0;
}
cout<< endl<< "completed";
}
//int BruteForce(int number)
//{
//}