/*水仙花数是指一个N位正整数(N>=3),它的海个位上的数字的N次幂之和等于它本身。例如:153=1^3+5^3+3^3.本题要求编写程序
计算所有N位水仙花数。*/
#include <stdio.h>
#include <math.h>
int main(void)
{
    int N;
    scanf("%d", &N);
    long limit = pow(10, N);
    long n, qianwan, baiwan, shiwan, wan, qian, hun, ten, ge, multi, sum;
    for (n = 100; n < limit; n++)
    {
        qianwan = n / 10000000 % 10;//千万 
        baiwan = n / 1000000 % 10;//百万 
        shiwan = n / 100000 % 10;//十万 
        wan = n / 10000 % 10;//求万位 
        qian = n / 1000 % 10;//求千位数 
        hun = n / 100 % 10; //求百位数
        ten = n / 10 % 10;  //求十位数
        ge = n % 10;        //求个位数
        multi = qianwan * 10000000 + baiwan * 1000000 + shiwan * 100000 + wan * 10000 + qian * 1000 + hun * 100 + ten * 10 + ge;
        sum = pow(qianwan, N) + pow(baiwan, N) + pow(shiwan, N) + pow(wan, N) + pow(qian, N) + pow(hun, N) + pow(ten, N) + pow(ge, N);
        if (sum == multi)
        {
            printf("%ld ", multi);
        }
    }
}