Ural 1014 Product of Digits NYOJ 270 数的分解 解题报告

题意:

是找到一个最小的正整数Q,使Q的各位数的乘积等于N。

思路:

从9到2取余。

#include <iostream>
#include <algorithm>
using namespace std;


bool fun(int x,int *ops,int &num)
{
if(x==1) return 1;
for(int i=9;i>=2;i--)
{
if(x%i==0)
{
ops[num]=i; //ops存储分解后的数集合
num++;
return fun(x/i,ops,num);
}
}
return 0;
}


int main()
{

int n;
while(cin>>n)
{if(n==0) cout<<10<<endl;
else if(n<=9) cout<<n<<endl;
else
{
int ops[11];
int num=0;
if(fun(n,ops,num))
{
sort(ops,ops+num);
for(int k=0;k<num;k++)
cout<<ops[k];
cout<<endl;
}

else
cout<<-1<<endl;
}
}
return 0;
}



原文地址:https://www.cnblogs.com/lazycoding/p/2305464.html