原题: https://vjudge.net/problem/UVA-993
很久之前没有做出来的题,今天偶然看到有了思路做了一下,就AC了,痕激动很开心,加油渣科!
#include<cstdio>
#include<set>
#include<math.h>
using namespace std;
//找9~2之间的因子,从大的找起,如果最后除不尽就返回-1,找到的压进multiset中
multiset<int>s1;
int find(int n)
{
for(int j=9;j>=2;j--)
{
if(n%j==0)
{
s1.insert(j);
n=n/j;
j=9;
}
}
if(n==1)
{
return 1;
}else{
return 0;
}
}
int main()
{
int n;
while(~scanf("%d",&n))
{
if(n<10)
{
printf("%d\n",n);
continue;
}
s1.clear();
int flag=find(n);
if(flag==0)
{
printf("-1\n");
}else{
multiset<int>::iterator it=s1.begin();
while(it!=s1.end())
{
printf("%d",*it);
it++;
}
printf("\n");
}
}
return 0;
}