uva 993 Product of digits (分解因子)
2015-03-08 11:07
281 查看
uva 993 Product of digits
题目大意:给定一个数N,要求出一个数,使得这个数的每一位相乘会等于N,且这个数的值最小。解题思路:简单的分解因子。要注意的地方有两点:1) 因子从9开始向2遍历,可以保证位数最小; 2)当N等于1是最好特殊处理。
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; int n, dig[100000]; int main() { int T; scanf("%d", &T); while (T--) { scanf("%d", &n); int flag = 0, cnt = 9, cnt2 = 0; if (n == 1) { printf("1\n"); continue; } while (n != 1) { if (cnt == 2 && n % cnt != 0) { flag = 0; break; } if (n % cnt != 0) { cnt--; } else { flag = 1; n /= cnt; dig[cnt2++] = cnt; cnt = 9; } } if (!flag) printf("-1\n"); else { for (int i = cnt2 - 1; i >= 0; i--) { printf("%d", dig[i]); } printf("\n"); } } return 0; }
相关文章推荐
- uva 993 Product of digits(分解因子)
- uva 993 Product of digits (贪心 + 分解因子)
- uva 993 Product of digits (贪心 + 分解因子)
- uva 10061 How many zero's and how many digits ?(在不同进制下分解因子)
- UVA 993 Product of digits 数字之积 贪心水题
- uva 993 Product of digits
- UVA - 993 Product of digits 贪心
- uva 10061 How many zero's and how many digits ?(在bas进制下分解因子)
- UVa 993: Product of digits
- [模拟]uva993 Product of digits
- UVA993 Product of digits【水题+字符串排序+不排序】
- uva993 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 10290 - {Sum+=i++} to Reach N(数论-整数因子分解)
- uva 10392 Factoring Large Numbers(分解因子)
- uva 993 - Product of digits