Given n, find the smallest number for which product of the digits is n, if no such number exists, print -1
int main()
{
int test;
scanf("%d",&test);
for(int i=0;i<test;i++)
{
int n;
scanf("%lld",&n);
int A[10]={0};
for(int j=9;j>;0;j--)
{
if(n==1)
break;
while(n%j==0)
{
A[j]++;
n/=j;
}
}
if(n>;1)
{
printf("-1\n");
continue;
}
for(int j=2;j<;10;j++)
{
while(A[j]>;0)
{
A[j]--;
printf("%d",j);
}
}
printf("\n");
}
return 0;
}
Read full article from Given n, find the smallest num... | CareerCup