A

来源:互联网 发布:手机淘宝网页版 编辑:程序博客网 时间:2024/05/16 07:51
Your task is to find the minimal positive integer number Q so that the product of digits of Q is exactly equal to N.

Input
The input contains the single integer number N (0 ≤ N ≤ 10 9).
Output
Your program should print to the output the only number Q. If such a number does not exist print −1.
Example
input

10

output

25

题意:输出的数的两个数位相乘刚好等于输入 的数,有两个坑点,一个是输入0的时候输出10,还有一个就是输出-1的情况是除到不能再除的时候那个数必须小于10.

#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){    int i,n,a[1000];    int count;    while(~scanf("%d",&n))    {        if(n==0)        {            printf("10\n");        }        else if(n<10)            printf("%d\n",n);        else        {            count = 0;            for(i=9;i>=2;i--)            {               while(n%i==0&&n!=1)               {                    a[count++] = i;                    n/=i;               }            }            if(n > 10)               printf("-1\n");            else            {                for(i=count-1;i>=0;i--)                {                    printf("%d",a[i]);                }                printf("\n");            }        }    }    return 0;}
原创粉丝点击