题解 | #变种水仙花#递归法

变种水仙花

https://www.nowcoder.com/practice/c178e3f5cc4641dfbc8b020ae79e2b71

#include <stdio.h>

long long Pan(long long i,long long a)
{
    long long b = i / a;
    long long c = i % a;
    long long d = b * c;
    a = a * 10;
    if (b == 0)
        return 0;
    else
        return d + Pan(i, a);
}
int main()
{
    long long i = 10000;
    long long a = 10;
    for (; i <= 99999; i++)
    {
        long long e= Pan(i,a);
        if (e == i)
            printf("%lld ", i);
    }
    return 0;
 }

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务