uva--993Product of digits
来源:互联网 发布:ubuntu安装openssh 编辑:程序博客网 时间:2024/04/28 02:30
水题一枚,如果n能分解成2--9的因子相乘的形式的话肯定是可以的,如果不行那么就直接输出-1;
那么当能分解的时候,为了能使得答案的值最小,我们选择先分解大的因子;也就是按9--2的次序进行分解。
分解后直接按因子从小到大输出就是答案了。
代码如下:
#include<iostream>#include<cstring>#include<cstdio>using namespace std;int main(){ int i,j,k,t,ans[50]; long long n; scanf("%d",&t); while(t--) { k=0; scanf("%lld",&n); if(n==1) { printf("1\n"); continue; } for(i=9;i>=2;i--) while(n%i==0) { ans[k++]=i; n=n/i; } if(n>10) { printf("-1\n"); continue; } for(i=k-1;i>=0;i--) printf("%d",ans[i]); printf("\n"); } return 0;}
1 0
- UVa 993 - Product of digits
- UVa 993 - Product of digits
- uva 993 - Product of digits
- uva 993 - Product of digits
- UVA 993 Product of digits
- UVa 993 - Product of digits
- Uva 993 Product Of Digits
- UVA 993 - Product of digits
- uva 993 - Product of digits
- UVa 993: Product of digits
- UVa:993 Product of digits
- uva 993 Product of digits
- uva 993 Product of digits
- uva 993 Product of digits
- uva 993 - Product of digits
- UVA 993 Product of digits
- UVa 993 - Product of digits
- UVA 993 Product of digits
- Redis基础之有序集合
- HDU_4099_Revenge of Fibonacci_Trie树,高精度
- Oracle零基础学习第三次课----表、字段类型、约束
- 进程环境
- java类的初始化顺序
- uva--993Product of digits
- Java-前奏
- Linux目录文件
- 隐马尔可夫模型(HMM)攻略
- javaweb学习总结(八)——HttpServletResponse对象(二)
- Java andorid layout
- WPF lisview 绑定数据
- OC基础语法<1.1> 入门面向对象语法-OC类、点语法
- HDU4841 圆桌问题 【HDU最烂题】