A - Product of Digits URAL - 1014(数位操作)
2017-12-11 17:17
225 查看
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; }
相关文章推荐
- URAL1014 - Product of Digits - 数论
- 10 URAL 1014 Product of Digits
- Ural1014-Product of Digits
- Ural 1014 Product of Digits 解题报告
- Ural 1014 Product of Digits NYOJ 270 数的分解 解题报告
- URAL 1014 Product of Digits 贪心
- Ural 1014 Product of Digits 解题报告
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- Ural 1014-The Product of Digits
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- URAL 1014 Product of Digits
- ural 1014 Product of Digits
- ural 1014 the product of digits
- URAL 1014 Product of Digits
- Amount of Degrees URAL - 1057 数位dp
- URAL 1057 数位dp
- 网易面试之对于一个整数X,定义操作rev(X)为将X按数位翻转过来,并且去除掉前导0
- UVA993 Product of digits【水题+字符串排序+不排序】
- ural1057(数位dp)
- ural 1057(数位dp)