10 URAL 1014 Product of Digits
2015-04-29 22:18
225 查看
找一个最小的正整数Q,Q的各个位置上的数字乘积等于N。
每一位只能是2-9,0和1没有用,那么能用尽量大的数就先用大的数,这样保证Q的位数最少,
从9枚举到2,如果W的因子只有9-2,那么有解,在把这些因子从小到大输出即可,否则无解。
注意要特判0和1,因为要求最小正整数,所以0的时候答案应该是10.
每一位只能是2-9,0和1没有用,那么能用尽量大的数就先用大的数,这样保证Q的位数最少,
从9枚举到2,如果W的因子只有9-2,那么有解,在把这些因子从小到大输出即可,否则无解。
注意要特判0和1,因为要求最小正整数,所以0的时候答案应该是10.
#include<cstdio> int main() { int i,n,cnt,ans[40]; while(~scanf("%d",&n)) { if(n==0) printf("10\n",n); else if(n<10) printf("%d\n",n); else { cnt=0; for(i=9;i>=2&&n!=1;i--) { while(n%i==0&&n!=1) { ans[cnt++]=i; n/=i; } } if(n!=1) puts("-1"); else { for(i=cnt-1;i>=0;i--) printf("%d",ans[i]); puts(""); } } } return 0; }
相关文章推荐
- A - Product of Digits URAL - 1014(数位操作)
- URAL1014 - Product of Digits - 数论
- Ural 1014 Product of Digits 解题报告
- URAL 1014 Product of Digits 贪心
- Ural1014-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(利用数据有序化进行贪心选择)
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- Ural 1014-The Product of Digits
- URAL 1014 Product of Digits
- ural 1014 Product of Digits
- ural 1014 the product of digits
- UVA993 Product of digits【水题+字符串排序+不排序】
- ural 1209. 1,10,100,1000.....
- [模拟]uva993 Product of digits
- How to arrange 10 digits so that the product of the some of them is equal to a number represented by the remaining digits
- uva993 - Product of digits-------------水题 1A
- How to arrange 10 digits so that the product of the some of them is equal to a number represented by the remaining digits