10 URAL 1014 Product of Digits

前端之家收集整理的这篇文章主要介绍了10 URAL 1014 Product of Digits前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

找1个最小的正整数QQ的各个位置上的数字乘积等于N

每位只能是2⑼,0和1没有用,那末能用尽可能大的数就先用大的数,这样保证Q的位数最少,

从9枚举到2,如果W的因子只有9⑵,那末有解,在把这些因子从小到大输出便可,否则无解。

注意要特判0和1,由于要求最小正整数,所以0的时候答案应当是10.


@H_301_18@#include<cstdio> int main() { int i,n,cnt,ans[40]; while(~scanf("%d",&n)) { if(n==0) printf("10 ",n); else if(n<10) printf("%d ",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("⑴"); else { for(i=cnt⑴;i>=0;i--) printf("%d",ans[i]); puts(""); } } } return 0; }



猜你在找的PHP相关文章