题解 | #变种水仙花#
变种水仙花
https://www.nowcoder.com/practice/c178e3f5cc4641dfbc8b020ae79e2b71
//#include <stdio.h>
/*
int main()
{
int n = 0;
for (n = 10000;n <= 99999;n++)
{
if ((((n / 10000) * (n % 10000)) + ((n / 1000) * (n % 1000)) + ((n / 100) * (n % 100)) + ((n / 10) * (n % 10))) == n)
{
printf("%d ", n);
}
}
return 0;
}
*/
#include<math.h>
#include<stdio.h>
int main()
{
int n = 0;
int i = 0;
int j = 0;
for (n = 10000;n < 99999;n++)
{
int ret = 0;
for (i = 1;i <= 4;i++)
{
int k = pow(10, i);
int j = (n % k) * (n / k);
ret = j + ret;
}
if (ret == n)
{
printf("%d ", n);
}
}
return 0;
}

查看14道真题和解析