幸运数

系统输入一个整数 x, x>0。你需要找到一个数,使它的每一位的数字相乘之后的积等于 x。如果没有答案,则返回 0;不超过 32 位整数;如果有多个答案,返回最小的那个。
测试举例
输入:48
输出:68

#include 
using namespace std;
int a(int n)
{
    int mul=1;
    while(n)
    {
        mul*=n%10;
        n/=10;
    }
    return mul;
}
int main()
{
    int m=0,mul,i=1,flag=0;
    cin>>m;
    for(i=1;i<10000;i++)
    {
        if(a(i)==m)
        {
            flag=1;
            break;
        }
    }
    if(flag)
    {
        cout<<i;
    }
    else
    {
        cout<<-1;
    }
    return 0;
}

你可能感兴趣的:(c++,c语言,c#)